Commit 3088fd51 authored by rockyl's avatar rockyl

Merge branch 'res-group' into dev

# Conflicts:
#	src/zeroing/game-warpper/GameStage.ts
#	src/zeroing/game-warpper/StackContainer.ts
#	src/zeroing/game-warpper/assets-manager.ts
parents fecd5a63 711d9001
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/zeroing-engine.iml" filepath="$PROJECT_DIR$/.idea/zeroing-engine.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{"id":"engine","url":"engine.d2f4eafa108b00ed5ac00e2d30ee98f8af4a9118.js"} {"id":"engine","url":"engine.dee8bb73f7c234c7fe2527549add0fab7ca3d3fc.js"}
\ No newline at end of file \ No newline at end of file
...@@ -439,41 +439,40 @@ export default class Container extends DisplayObject { ...@@ -439,41 +439,40 @@ export default class Container extends DisplayObject {
this._lastBoundsID = this._boundsID this._lastBoundsID = this._boundsID
this._bounds.clear(); this._bounds.clear();
//算自己的 //算自己的
this._calculateBounds(); if(!this._calculateBounds()){
for (let i = 0; i < this.children.length; i++) { for (let i = 0; i < this.children.length; i++) {
const child = this.children[i]; const child = this.children[i];
if (!child.visible || !child.renderable) { if (!child.visible || !child.renderable) {
continue; continue;
}
child.calculateBounds();
if (child.$mask) {
child.$mask.calculateBounds();
//取交集矩形
if (child._bounds.x < child.$mask._bounds.x) {
child._bounds.x = child.$mask._bounds.x;
}
if (child._bounds.y < child.$mask._bounds.y) {
child._bounds.y = child.$mask._bounds.y;
} }
if (child._bounds.width > child.$mask._bounds.width) { child.calculateBounds();
child._bounds.width = child.$mask._bounds.width; if (child.$mask) {
} child.$mask.calculateBounds();
if (child._bounds.height > child.$mask._bounds.height) { //取交集矩形
child._bounds.height = child.$mask._bounds.height; if (child._bounds.x < child.$mask._bounds.x) {
child._bounds.x = child.$mask._bounds.x;
}
if (child._bounds.y < child.$mask._bounds.y) {
child._bounds.y = child.$mask._bounds.y;
}
if (child._bounds.width > child.$mask._bounds.width) {
child._bounds.width = child.$mask._bounds.width;
}
if (child._bounds.height > child.$mask._bounds.height) {
child._bounds.height = child.$mask._bounds.height;
}
Rectangle.createFromRects(this._bounds, child._bounds);
} else {
Rectangle.createFromRects(this._bounds, child._bounds);
} }
Rectangle.createFromRects(this._bounds, child._bounds);
} else {
Rectangle.createFromRects(this._bounds, child._bounds);
} }
} }
} }
/** /**
* 加"_"的方法基本是为了自己特殊处理 * 加"_"的方法基本是为了自己特殊处理
*/ */
protected _calculateBounds() { protected _calculateBounds(): boolean {
//子类自己重写 //子类自己重写
//let wp = this.worldMatrix.transformPoint(this.x, this.y); //let wp = this.worldMatrix.transformPoint(this.x, this.y);
...@@ -496,7 +495,10 @@ export default class Container extends DisplayObject { ...@@ -496,7 +495,10 @@ export default class Container extends DisplayObject {
matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3); matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3);
matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4); matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4);
Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4); Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
return true;
} }
return false;
} }
/** /**
...@@ -704,7 +706,8 @@ export default class Container extends DisplayObject { ...@@ -704,7 +706,8 @@ export default class Container extends DisplayObject {
* @member {number} * @member {number}
*/ */
get width(): number { get width(): number {
return this._width || this.scale.x * this.getLocalBounds().width; let value = this._width;
return !value && value != 0 ? this.scale.x * this.getLocalBounds().width : value;
} }
set width(value: number) { set width(value: number) {
...@@ -716,10 +719,14 @@ export default class Container extends DisplayObject { ...@@ -716,10 +719,14 @@ export default class Container extends DisplayObject {
// this.scale.x = 1; // this.scale.x = 1;
// } // }
if (this._width !== value) { if (this._width !== value) {
//子类有用,有_width,才需设置scaleX if (!value && value != 0) {
this._width = value; this._width = undefined;
this._localBoundsSelf.width = value; } else {
//if (this.stage) this.stage.layoutInvalid = true; //子类有用,有_width,才需设置scaleX
this._width = value;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
} }
} }
...@@ -729,7 +736,8 @@ export default class Container extends DisplayObject { ...@@ -729,7 +736,8 @@ export default class Container extends DisplayObject {
* @member {number} * @member {number}
*/ */
get height(): number { get height(): number {
return this._height || this.scale.y * this.getLocalBounds().height; let value = this._height;
return !value && value != 0 ? this.scale.y * this.getLocalBounds().height : value;
} }
set height(value: number) { set height(value: number) {
...@@ -740,10 +748,14 @@ export default class Container extends DisplayObject { ...@@ -740,10 +748,14 @@ export default class Container extends DisplayObject {
// } else { // } else {
// this.scale.y = 1; // this.scale.y = 1;
// } // }
if (this._height !== value) { if (!value && value != 0) {
this._height = value; this._height = undefined;
this._localBoundsSelf.height = value; } else {
//if (this.stage) this.stage.layoutInvalid = true; if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
} }
} }
......
...@@ -94,9 +94,9 @@ export default class Sprite extends Container { ...@@ -94,9 +94,9 @@ export default class Sprite extends Container {
this._texture = null; this._texture = null;
this._width = 0; //this._width = 0;
this._height = 0; //this._height = 0;
this._tint = null; this._tint = null;
this._tintRGB = null; this._tintRGB = null;
...@@ -391,14 +391,22 @@ export default class Sprite extends Container { ...@@ -391,14 +391,22 @@ export default class Sprite extends Container {
* @member {number} * @member {number}
*/ */
get width() { get width() {
return Math.abs(this.scale.x) * this._texture.orig.width; let value = this._width;
return !value && value != 0 ? Math.abs(this.scale.x) * this._texture.orig.width : value;
} }
set width(value) { set width(value) {
const s = sign(this.scale.x) || 1; if (this._width !== value) {
if (!value && value != 0) {
this.scale.x = s * value / this._texture.orig.width; this.scale.x = 1;
this._width = value; this._width = undefined;
} else {
const s = sign(this.scale.y) || 1;
this.scale.x = s * value / this._texture.orig.width;
this._width = value;
}
this.dispatchEvent(Event.RESIZE);
}
} }
/** /**
...@@ -406,13 +414,22 @@ export default class Sprite extends Container { ...@@ -406,13 +414,22 @@ export default class Sprite extends Container {
* @member {number} * @member {number}
*/ */
get height() { get height() {
return Math.abs(this.scale.y) * this._texture.orig.height; let value = this._height;
return !value && value != 0 ? Math.abs(this.scale.y) * this._texture.orig.height : value;
} }
set height(value) { set height(value) {
const s = sign(this.scale.y) || 1; if (this._height !== value) {
this.scale.y = s * value / this._texture.orig.height; if (!value && value != 0) {
this._height = value; this.scale.y = 1;
this._height = undefined;
} else {
const s = sign(this.scale.y) || 1;
this.scale.y = s * value / this._texture.orig.height;
this._height = value;
}
this.dispatchEvent(Event.RESIZE);
}
} }
/** /**
......
...@@ -559,7 +559,7 @@ export class Stage extends Container { ...@@ -559,7 +559,7 @@ export class Stage extends Container {
* @return {{w: number, h: number}} * @return {{w: number, h: number}}
*/ */
public getRootDivWH(div: HTMLDivElement) { public getRootDivWH(div: HTMLDivElement) {
let sw = div.style.width; /*let sw = div.style.width;
let sh = div.style.height; let sh = div.style.height;
let iw = document.body.clientWidth; let iw = document.body.clientWidth;
// let ih = document.body.clientHeight-40; // let ih = document.body.clientHeight-40;
...@@ -580,7 +580,11 @@ export class Stage extends Container { ...@@ -580,7 +580,11 @@ export class Stage extends Container {
vH *= ih / 100; vH *= ih / 100;
} }
} }
return {w: vW, h: vH}; return {w: vW, h: vH};*/
let divBound = div.getBoundingClientRect();
let w = divBound.width;
let h = divBound.height;
return {w, h};
} }
/** /**
......
...@@ -169,28 +169,42 @@ export class TextField extends Sprite { ...@@ -169,28 +169,42 @@ export class TextField extends Sprite {
// private _textHeight: number = 0; // private _textHeight: number = 0;
get width(): number { get width(): number {
if (this._width) return this._width; if (!this._width && this._width != 0) {
this.updateText(); this.updateText();
return this.scale.x * this.getLocalBounds().width; return this.scale.x * this.getLocalBounds().width;
} else {
return this._width;
}
} }
set width(value: number) { set width(value: number) {
if (this._width !== value) { if (this._width !== value) {
this._width = value; if (!value && value != 0) {
this._width = undefined;
} else {
this._width = value;
}
this.dirty = true; this.dirty = true;
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
} }
} }
get height(): number { get height(): number {
if (this._height) return this._height; if (!this._height && this._height != 0) {
this.updateText(); this.updateText();
return this.scale.y * this.getLocalBounds().height; return this.scale.y * this.getLocalBounds().height;
} else {
return this._height;
}
} }
set height(value: number) { set height(value: number) {
if (this._height !== value) { if (this._height !== value) {
this._height = value; if (!value && value != 0) {
this._height = undefined;
} else {
this._height = value;
}
this.dirty = true; this.dirty = true;
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
} }
...@@ -691,7 +705,7 @@ export class TextField extends Sprite { ...@@ -691,7 +705,7 @@ export class TextField extends Sprite {
s.realLines = realLines; s.realLines = realLines;
s._prepContext(ctx); s._prepContext(ctx);
let textWidth = s._width; let textWidth = !s._width && s._width != 0 ? 0 : s._width;
// let lineH = s._lineSpacing + s.size; // let lineH = s._lineSpacing + s.size;
//单行文本时 //单行文本时
if (isPureText && text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) { if (isPureText && text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
...@@ -719,7 +733,7 @@ export class TextField extends Sprite { ...@@ -719,7 +733,7 @@ export class TextField extends Sprite {
} }
} else { } else {
//textWidth取每行最大值,如果没设置过textWidth //textWidth取每行最大值,如果没设置过textWidth
const shouldMeasureTextWidth = !textWidth; const shouldMeasureTextWidth = !s._width && s._width != 0 ? true : false;
let index = 0; let index = 0;
for (let i = 0, l = hardLines.length; i < l; i++) { for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i]; let str = hardLines[i];
...@@ -906,6 +920,19 @@ export class TextField extends Sprite { ...@@ -906,6 +920,19 @@ export class TextField extends Sprite {
} }
} }
/**
* 更新自己的bounds,计算全局
* @private
*/
_calculateBounds() {
const {width, height} = this._localBoundsSelf;
var matrix = this.transform.worldMatrix;
this._bounds.x = matrix.tx;
this._bounds.y = matrix.ty;
this._bounds.width = width;
this._bounds.height = height;
}
/** /**
* 更新texture及baseTexture属性 * 更新texture及baseTexture属性
* 不考虑trim, * 不考虑trim,
......
This diff is collapsed.
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
import {DisplayObject} from "../../2d/display/index"; import {DisplayObject} from "../../2d/display/index";
import {Node} from "./nodes/Node"; import {Node} from "./nodes/Node";
import {Event} from "../../2d/events/Event";
import {playViewEffect} from "./view-effects";
/** /**
* 栈式视图容器 * 栈式视图容器
...@@ -11,77 +13,214 @@ import {Node} from "./nodes/Node"; ...@@ -11,77 +13,214 @@ import {Node} from "./nodes/Node";
export class StackContainer extends Node { export class StackContainer extends Node {
private _mutex: boolean; private _mutex: boolean;
private _stack = []; private _stack = [];
private _inserted = 0;
constructor(mutex = true) { private _playing = false;
private _actionQueue = [];
constructor(mutex = true, inserted = 0) {
super(); super();
this._mutex = mutex; this._mutex = mutex;
this._inserted = inserted;
this.percentWidth = 100; this.percentWidth = 100;
this.percentHeight = 100; this.percentHeight = 100;
this.mouseEnabled = false; this.mouseEnabled = false;
this.addEventListener(Event.START, () => {
this.mouseChildren = false;
});
this.addEventListener(Event.COMPLETE, () => {
this.mouseChildren = true;
});
}
get childNum() {
let len = this.children.length;
return len > 0 ? len - this._inserted : 0;
} }
/** /**
* 推入视图 * 推入视图
* @param view * @param view
* @param options * @param options
* @param dispatch * @param playEffect
*/ */
push(view: DisplayObject, options?, dispatch = true) { push(view: DisplayObject, options?, playEffect = true) {
if (this._mutex && this.children.length > 0) { this._actionQueue.push({action: 'push', args: arguments});
this._stack.push(this.removeChildAt(0)); this._playNextAction();
}
this.addChild(view);
if (dispatch) {
this.dispatchEvent('change', {action: 'push', view, options});
}
} }
/** /**
* 替换顶层视图 * 撤出视图
* @param view
* @param options * @param options
* @param playEffect
*/ */
replace(view: DisplayObject, options?) { pop(options?, playEffect = true) {
if (this.pop(false)) { this._actionQueue.push({action: 'pop', args: arguments});
this.push(view, options, false); this._playNextAction();
this.dispatchEvent('change', {action: 'replace', view, options});
}
} }
/** /**
* 撤出视图 * 替换顶层视图
* @param view
* @param options
* @param playEffect
*/ */
pop(dispatch = true) { replace(view: DisplayObject, options?, playEffect = true) {
let len = this.children.length; this._actionQueue.push({action: 'replace', args: arguments});
if (len <= 0) { this._playNextAction();
return false;
}
this.removeChildAt(len - 1);
if (this._mutex) {
this.addChild(this._stack.pop());
}
if (dispatch) {
this.dispatchEvent('change', {action: 'pop'});
}
return true;
} }
/** /**
* 撤出全部视图 * 撤出全部视图
* @param view * @param view
* @param options * @param options
* @param playEffect
*/ */
popAll(view?: DisplayObject, options?) { popAll(view?: DisplayObject, options?, playEffect = true) {
this.removeChildren(); this._actionQueue.push({action: 'popAll', args: arguments});
if (this._mutex) { this._playNextAction();
this._stack.splice(0); }
private _playNextAction = () => {
if (this._playing || this._actionQueue.length === 0) {
return;
} }
if (view) {
this.push(view, options, false); let actionItem = this._actionQueue.shift();
let args = [];
for (let i = 0, li = actionItem.args.length; i < li; i++) {
const argument = actionItem.args[i];
args.push(argument);
} }
this.dispatchEvent('change', {action: 'popAll', view, options}); this._playing = true;
this['_' + actionItem.action].apply(this, args)
.then(()=>{
this._playing = false;
setTimeout(this._playNextAction, 1);
});
};
private _push(view: DisplayObject, options?, playEffect = true) {
return new Promise(resolve => {
const action = 'push';
let lastView;
if (this._mutex && this.childNum > 0) {
lastView = this.getChildAt(0);
this._stack.push(lastView);
}
view.visible = false;
this.addChild(view);
let data = {action, view, lastView, options, hasView: true};
this.dispatchEvent(Event.START, data);
playViewEffect(
playEffect ? options ? options.effect : null : null,
options ? options.effectParams : {},
this._mutex, lastView, view, this,
() => {
this.dispatchEvent(Event.COMPLETE, data);
resolve();
}
)
})
}
private _pop(options?, playEffect = true) {
return new Promise(resolve => {
const action = 'pop';
let len = this.childNum;
if (len <= 0) {
return false;
}
let lastView = this.getChildAt(this.children.length - 1);
let view;
if (this._mutex) {
view = this._stack.pop();
view.visible = false;
this.addChild(view);
}
let data = {action, view, lastView, options, hasView: len > 1};
this.dispatchEvent(Event.START, data);
playViewEffect(
playEffect ? options ? options.effect : null : null,
options ? options.effectParams : {},
this._mutex, lastView, view, this,
() => {
this.dispatchEvent(Event.COMPLETE, data);
resolve();
}
)
})
}
private _replace(view: DisplayObject, options?, playEffect = true) {
return new Promise(resolve => {
const action = 'replace';
let len = this.childNum;
if (len <= 0) {
return false;
}
let lastView = this.getChildAt(len - 1);
view.visible = false;
this.addChild(view);
let data = {action, view, lastView, options, hasView: len > 1};
this.dispatchEvent(Event.START, data);
playViewEffect(
playEffect ? options ? options.effect : null : null,
options ? options.effectParams : {},
this._mutex, lastView, view, this,
() => {
this.dispatchEvent(Event.COMPLETE, data);
resolve();
}
)
})
}
private _popAll(view?: DisplayObject, options?, playEffect = true) {
return new Promise(resolve => {
const action = 'popAll';
let len = this.childNum;
if(len == 0){
resolve();
return;
}
let lastView = this.getChildAt(len);
while (this.children.length > 2) {
this.removeChildAt(0);
}
if (this._mutex) {
this._stack.splice(0);
}
if (view) {
view.visible = false;
this.addChild(view);
}
let data = {action, view, lastView, options, hasView: false};
this.dispatchEvent(Event.START, data);
playViewEffect(
playEffect ? options ? options.effect : null : null,
options ? options.effectParams : {},
this._mutex, lastView, view, this,
() => {
this.dispatchEvent(Event.COMPLETE, data);
resolve();
}
)
})
} }
} }
\ No newline at end of file
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
*/ */
import {globalLoader} from "../../2d/loader/Loader"; import {globalLoader} from "../../2d/loader/Loader";
import {arrayFind, linkScheme} from "../utils"; import {arrayFind, linkScheme} from "../utils/index";
import {parse} from "./bmp-text-manager"; import {parse} from "./bmp-text-manager";
import {globalEvent} from "../decorators/events";
let assetsConfig = []; let assetsConfig = [];
...@@ -22,10 +23,89 @@ const loaderMapping = { ...@@ -22,10 +23,89 @@ const loaderMapping = {
'': 'Raw', '': 'Raw',
}; };
const assetGroupLoaded = {};
const assetGroupLoading = {};
/**
* 检查资源组是否已加载
* @param groupName
*/
export function checkAssetGroupLoaded(groupName) {
return assetGroupLoaded[groupName]
}
/**
* 加载多个素材组
* @param groups
* @param onStart
* @param onFinish
*/
export async function loadAssetsGroups(groups, onStart?, onFinish?) {
let total = 0;
let loaded = 0;
for (let groupName in groups) {
if (!checkAssetGroupLoaded(groupName)) {
let depAssets = groups[groupName];
if (depAssets && depAssets.length > 0) {
total += depAssets.length;
}
}
}
onStart && await onStart();
for (let groupName in groups) {
if (!checkAssetGroupLoaded(groupName)) {
let depAssets = groups[groupName];
if (depAssets && depAssets.length > 0) {
await loadAssetsGroup(depAssets, groupName, () => {
loaded++;
globalEvent.dispatchEvent('load-assets-process', {loaded, total})
}, () => {
globalEvent.dispatchEvent('load-assets-complete');
});
}
}
}
await new Promise(resolve => {
setTimeout(resolve, 100);
});
onFinish && await onFinish();
}
/**
* 加载素材组
*/
export async function loadAssetsGroup(config, groupName, onProcess?, onComplete?) {
if (checkAssetGroupLoaded[groupName]) {
return
}
if (assetGroupLoading[groupName]) {
return new Promise((resolve, reject) => {
assetGroupLoading[groupName].push({resolve, reject})
});
} else {
assetGroupLoading[groupName] = [];
}
await loadAssets(config, onProcess, onComplete);
assetGroupLoaded[groupName] = true;
for (let p of assetGroupLoading[groupName]) {
p.resolve();
}
delete assetGroupLoading[groupName];
}
/** /**
* 加载素材 * 加载素材
*/ */
export function loadAssets(config, onProgress?, onComplete?) { export function loadAssets(config, onProgress?, onComplete?) {
if (!config) {
console.log();
}
let total = config.length; let total = config.length;
let loaded = 0; let loaded = 0;
let failedList = []; let failedList = [];
...@@ -33,27 +113,36 @@ export function loadAssets(config, onProgress?, onComplete?) { ...@@ -33,27 +113,36 @@ export function loadAssets(config, onProgress?, onComplete?) {
return Promise.all( return Promise.all(
config.map(assetConfig => { config.map(assetConfig => {
assetsConfig.push(assetConfig); assetsConfig.push(assetConfig);
const {url, ext, uuid} = assetConfig; if (assetConfig.url.indexOf(linkScheme) === 0) {
const loadFunc = loaderMapping[ext]; let linkUUID = assetConfig.url.replace(linkScheme, '');
if (loadFunc) { assetConfig = getAssetByUUID(linkUUID);
if(url.indexOf(linkScheme) === 0){ }
loaded++;
onProgress && onProgress(loaded, total); if (assetConfig) {
return Promise.resolve(); const {url, ext, uuid} = assetConfig;
const loadFunc = loaderMapping[ext];
if (loadFunc) {
let method = globalLoader['load' + loadFunc];
return method.call(globalLoader, url, uuid).then(
(data) => {
parse(assetConfig, data);
loaded++;
onProgress && onProgress(loaded, total);
},
(error) => {
failedList.push(url);
}
);
} else {
return p();
} }
let method = globalLoader['load' + loadFunc];
return method.call(globalLoader, url, uuid).then(
(data) => {
parse(assetConfig, data);
loaded++;
onProgress && onProgress(loaded, total);
},
(error) => {
failedList.push(url);
}
);
} else { } else {
return p();
}
function p() {
loaded++; loaded++;
onProgress && onProgress(loaded, total); onProgress && onProgress(loaded, total);
return Promise.resolve(); return Promise.resolve();
......
/**
* Created by rockyl on 2020-05-04.
*/
import {Tween} from "../../2d/tween/Tween";
import {gameStage} from "../launcher";
import {injectProp} from "../utils/index";
import {Ease} from "../../2d/tween/Ease";
export function playViewEffect(name, params, mutex, lastView, view, container, callback) {
let effect = name ? effects[name] : effects.simple;
effect = effect || effects.simple;
effect(params || {}, mutex, lastView, view, container, callback);
}
const effects = {
simple(params, mutex, lastView, view, container, callback) {
if (mutex) {
container.removeChild(lastView);
} else {
if (lastView && !view) {
container.removeChild(lastView);
}
}
if (view) {
if (!view.parent) {
container.addChild(view);
}
view.visible = true;
}
callback();
},
fade(params, mutex, lastView, view, container, callback) {
const {duration = 300} = params;
if (mutex) {
fadeOut(() => {
fadeIn(callback);
})
} else {
if (lastView && !view) {
fadeOut(callback)
} else {
fadeIn(callback);
}
}
function fadeOut(callback) {
if (lastView) {
Tween.get(lastView, null, null, true)
.to({alpha: 0}, duration)
.call(() => {
container.removeChild(lastView);
lastView.alpha = 1;
callback();
});
} else {
callback();
}
}
function fadeIn(callback) {
if (view) {
view.visible = true;
view.alpha = 0;
Tween.get(view, null, null, true)
.to({alpha: 1}, params.duration || 300)
.call(() => {
callback();
});
} else {
callback();
}
}
},
flew(params, mutex, lastView, view, container, callback) {
const {duration = 300, direction = 'top', ease = 'backOut', inPos: inPosInput} = params;
const {stage: {width, height}} = gameStage;
let outPos: any = {};
switch (direction) {
case 'left':
outPos.x = -width;
break;
case 'right':
outPos.x = width;
break;
case 'top':
outPos.y = -height;
break;
case 'bottom':
outPos.y = height;
break;
}
let inEase = ease;
let outEase = ease ? ease.indexOf('Out') ? ease.replace('Out', 'In') : ease.replace('In', 'Out') : '';
if (mutex) {
flewOut(() => {
flewIn(callback);
})
} else {
if (lastView && !view) {
flewOut(callback)
} else {
flewIn(callback);
}
}
function flewOut(callback) {
if (lastView) {
Tween.get(lastView, null, null, true)
.to(outPos, duration, Ease[outEase])
.call(() => {
container.removeChild(lastView);
injectProp(lastView, outPos);
callback();
});
} else {
callback();
}
}
function flewIn(callback) {
if (view) {
let inPos: any = {
x: inPosInput && inPosInput.hasOwnProperty('x') ? inPosInput.x : view.x,
y: inPosInput && inPosInput.hasOwnProperty('y') ? inPosInput.y : view.y,
};
view.visible = true;
injectProp(view, outPos);
Tween.get(view, null, null, true)
.to(inPos, duration, Ease[inEase])
.call(() => {
callback();
});
} else {
callback();
}
}
},
hulu(params, mutex, lastView, view, container, callback) {
const {duration = 300, ease = 'backOut', x = 0, y = 0} = params;
let inEase = ease;
let outEase = ease ? ease.indexOf('Out') ? ease.replace('Out', 'In') : ease.replace('In', 'Out') : '';
let outPos = {
x: parseInt(x),
y: parseInt(y),
scaleX: 0, scaleY: 0,
};
if (mutex) {
huluOut(() => {
huluIn(callback);
})
} else {
if (lastView && !view) {
huluOut(callback)
} else {
huluIn(callback);
}
}
function huluOut(callback) {
if (lastView) {
outPos.x -= lastView.width / 2;
outPos.y -= lastView.height / 2;
Tween.get(lastView, null, null, true)
.to(outPos, duration, Ease[outEase])
.call(() => {
container.removeChild(lastView);
injectProp(lastView, {scaleX: 1, scaleY: 1});
callback();
});
} else {
callback();
}
}
function huluIn(callback) {
if (view) {
let inPos: any = {
x: view.x,
y: view.y,
scaleX: 1, scaleY: 1
};
outPos.x -= view.width / 2;
outPos.y -= view.height / 2;
view.visible = true;
injectProp(view, outPos);
Tween.get(view, null, null, true)
.to(inPos, duration, Ease[inEase])
.call(() => {
view.anchorX = 0;
view.anchorY = 0;
callback();
});
} else {
callback();
}
}
},
zoom(params, mutex, lastView, view, container, callback) {
const {duration = 300, ease = 'backOut'} = params;
let inEase = ease;
let outEase = ease ? ease.indexOf('Out') ? ease.replace('Out', 'In') : ease.replace('In', 'Out') : '';
if (mutex) {
zoomOut(() => {
zoomIn(callback);
})
} else {
if (lastView && !view) {
zoomOut(callback)
} else {
zoomIn(callback);
}
}
function zoomOut(callback) {
if (lastView) {
Tween.get(lastView, null, null, true)
.to({scaleX: 0, scaleY: 0}, duration, Ease[outEase])
.call(() => {
container.removeChild(lastView);
injectProp(view, {scaleX: 1, scaleY: 1});
callback();
});
} else {
callback();
}
}
function zoomIn(callback) {
if (view) {
view.anchorX = view.width / 2;
view.anchorY = view.height / 2;
view.visible = true;
injectProp(view, {scaleX: 0, scaleY: 0});
Tween.get(view, null, null, true)
.to({scaleX: 1, scaleY: 1}, duration, Ease[inEase])
.call(() => {
view.anchorX = 0;
view.anchorY = 0;
callback();
});
} else {
callback();
}
}
},
};
...@@ -103,9 +103,9 @@ export function dealPageRemainTime() { ...@@ -103,9 +103,9 @@ export function dealPageRemainTime() {
} }
} }
export function accessLog(pagebizid, params?) { export function accessLog(pageBizId, params?) {
let p = { let p = {
pagebizid, pageBizId,
}; };
injectProp(p, params); injectProp(p, params);
return httpRequest('buriedPoint', 'get', p); return httpRequest('buriedPoint', 'get', p);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment