From 6c2ae3b4338c21ae20dd5084cc2ec75afdd76aae Mon Sep 17 00:00:00 2001 From: Sebastian Kupke Date: Fri, 29 Mar 2019 09:11:21 +0100 Subject: [PATCH] Removed Greensock ThrowPropsPlugin as an dependency. --- dist/iwmlib.pixi.js | 78 ++++++++++++++++++++++++++++++++++++-------- lib/pixi/list.js | 16 +++++---- lib/pixi/timeline.js | 11 +++++-- 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/dist/iwmlib.pixi.js b/dist/iwmlib.pixi.js index 836e9f4..8d0f0a8 100644 --- a/dist/iwmlib.pixi.js +++ b/dist/iwmlib.pixi.js @@ -11306,8 +11306,8 @@ * @param {*} text * @param {*} style * @param {*} width - * @returns * @memberof Hypenate + * @returns {string} */ static splitLines(text, style, width) { const pixiStyle = new PIXI.TextStyle(style); @@ -11322,6 +11322,47 @@ } } + class TextLabel extends PIXI.Text { + + /** + *Creates an instance of TextLabel. + * @param {string} text - The string that you would like the text to display + * @param {object|PIXI.TextStyle} [style] - The style parameters + * @param {canvas} + * @memberof TextLabel + */ + constructor(text, style=null, canvas=null, { minZoom = 0.1, maxZoom = 10} = {}) { + super(text, style, canvas ); + this.normFontSize = this.style.fontSize; + this.minZoom = minZoom; + this.maxZoom = maxZoom; + } + + zoom(factor) { + let oldValue = parseFloat(this.style.fontSize) / this.normFontSize; + let value = oldValue * factor; + this.setZoom(value); + } + + setZoom(value) { + let oldValue = parseFloat(this.style.fontSize) / this.normFontSize; + if (value > this.maxZoom) { + value = this.maxZoom; + } + if (value < this.minZoom) { + value = this.minZoom; + } + if (value != oldValue) { + this.style.fontSize = Math.max(value * this.normFontSize, 1); + } + } + + setZoomAndScale(scale) { + this.scale.set(1 / scale); + this.setZoom(scale); + } + } + /** * A specialization of the PIXI.Graphics class that allows to * resuse and place labels across different layout variants @@ -11343,7 +11384,7 @@ } _createText(label, fontInfo) { - return new PIXI.Text(label, fontInfo) + return new TextLabel(label, fontInfo) } @@ -11360,7 +11401,7 @@ * maxHeight: {number} truncates text that needs more space and adds ellipsis * maxWidth: {number} word wraps text using hyphenation if possible * @param {*} [fontInfo=FontInfo.normal] - Defines PIXI.TextStyle attributes - * @returns {PIXI.Text} instance + * @returns {PIXI.Text} - instance * @memberof LabeledGraphics */ ensureLabel(key, label, attrs = {}, fontInfo = FontInfo.normal) { @@ -11429,7 +11470,7 @@ * @param {*} text * @param {*} style * @param {*} [maxLines=Infinity] - * @returns + * @returns {string} * @memberof LabeledGraphics */ truncateLabel(text, style, maxLines = Infinity) { @@ -11465,7 +11506,7 @@ * Returns the label for the given key. * * @param {*} key - * @returns + * @returns {Object} * @memberof LabeledGraphics */ getLabel(key) { @@ -12195,7 +12236,9 @@ this.killTweens(); this.deltas = []; this.validScroll(); - ThrowPropsPlugin.track(this, 'delta'); + if (typeof ThrowPropsPlugin != "undefined") { + ThrowPropsPlugin.track(this, 'delta'); + } } onMove(event, interaction) { @@ -12212,8 +12255,11 @@ } onEnd(event, interaction) { - let vel = ThrowPropsPlugin.getVelocity(this, 'delta'); - ThrowPropsPlugin.untrack(this); + + if (typeof ThrowPropsPlugin != "undefined") { + let vel = ThrowPropsPlugin.getVelocity(this, 'delta'); + ThrowPropsPlugin.untrack(this); + } this.killTweens(); this.redraw(); @@ -13863,7 +13909,9 @@ }; TweenLite.killTweensOf(this.container.position, {x: true, y: true}); - ThrowPropsPlugin.track(this.container.position, 'x,y'); + if (typeof ThrowPropsPlugin != "undefined") { + ThrowPropsPlugin.track(this.container.position, 'x,y'); + } } /** @@ -13917,11 +13965,13 @@ }; } - ThrowPropsPlugin.to(this.container.position, { - throwProps, - ease: Strong.easeOut, - onComplete: () => ThrowPropsPlugin.untrack(this.container.position) - }, .8, .4); + if (typeof ThrowPropsPlugin != "undefined") { + ThrowPropsPlugin.to(this.container.position, { + throwProps, + ease: Strong.easeOut, + onComplete: () => ThrowPropsPlugin.untrack(this.container.position) + }, .8, .4); + } } } diff --git a/lib/pixi/list.js b/lib/pixi/list.js index 42ffa5f..6b717b6 100644 --- a/lib/pixi/list.js +++ b/lib/pixi/list.js @@ -258,7 +258,9 @@ export default class List extends PIXI.Container { } TweenLite.killTweensOf(this.container.position, {x: true, y: true}) - ThrowPropsPlugin.track(this.container.position, 'x,y') + if (typeof ThrowPropsPlugin != "undefined") { + ThrowPropsPlugin.track(this.container.position, 'x,y') + } } /** @@ -312,11 +314,13 @@ export default class List extends PIXI.Container { } } - ThrowPropsPlugin.to(this.container.position, { - throwProps, - ease: Strong.easeOut, - onComplete: () => ThrowPropsPlugin.untrack(this.container.position) - }, .8, .4) + if (typeof ThrowPropsPlugin != "undefined") { + ThrowPropsPlugin.to(this.container.position, { + throwProps, + ease: Strong.easeOut, + onComplete: () => ThrowPropsPlugin.untrack(this.container.position) + }, .8, .4) + } } } diff --git a/lib/pixi/timeline.js b/lib/pixi/timeline.js index 719048c..d0f5ac2 100644 --- a/lib/pixi/timeline.js +++ b/lib/pixi/timeline.js @@ -745,7 +745,9 @@ export default class Timeline extends BitmapLabeledGraphics { this.killTweens() this.deltas = [] this.validScroll() - ThrowPropsPlugin.track(this, 'delta') + if (typeof ThrowPropsPlugin != "undefined") { + ThrowPropsPlugin.track(this, 'delta') + } } onMove(event, interaction) { @@ -762,8 +764,11 @@ export default class Timeline extends BitmapLabeledGraphics { } onEnd(event, interaction) { - let vel = ThrowPropsPlugin.getVelocity(this, 'delta') - ThrowPropsPlugin.untrack(this) + + if (typeof ThrowPropsPlugin != "undefined") { + let vel = ThrowPropsPlugin.getVelocity(this, 'delta') + ThrowPropsPlugin.untrack(this) + } this.killTweens() this.redraw()