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"}
\ No newline at end of file
{"id":"engine","url":"engine.dee8bb73f7c234c7fe2527549add0fab7ca3d3fc.js"}
\ No newline at end of file
......@@ -439,7 +439,7 @@ export default class Container extends DisplayObject {
this._lastBoundsID = this._boundsID
this._bounds.clear();
//算自己的
this._calculateBounds();
if(!this._calculateBounds()){
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
if (!child.visible || !child.renderable) {
......@@ -466,14 +466,13 @@ export default class Container extends DisplayObject {
Rectangle.createFromRects(this._bounds, child._bounds);
}
}
}
}
/**
* 加"_"的方法基本是为了自己特殊处理
*/
protected _calculateBounds() {
protected _calculateBounds(): boolean {
//子类自己重写
//let wp = this.worldMatrix.transformPoint(this.x, this.y);
......@@ -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.y + rect.height, 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 {
* @member {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) {
......@@ -716,10 +719,14 @@ export default class Container extends DisplayObject {
// this.scale.x = 1;
// }
if (this._width !== value) {
if (!value && value != 0) {
this._width = undefined;
} else {
//子类有用,有_width,才需设置scaleX
this._width = value;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
}
}
......@@ -729,7 +736,8 @@ export default class Container extends DisplayObject {
* @member {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) {
......@@ -740,10 +748,14 @@ export default class Container extends DisplayObject {
// } else {
// this.scale.y = 1;
// }
if (!value && value != 0) {
this._height = undefined;
} else {
if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
}
}
......
......@@ -94,9 +94,9 @@ export default class Sprite extends Container {
this._texture = null;
this._width = 0;
//this._width = 0;
this._height = 0;
//this._height = 0;
this._tint = null;
this._tintRGB = null;
......@@ -391,29 +391,46 @@ export default class Sprite extends Container {
* @member {number}
*/
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) {
const s = sign(this.scale.x) || 1;
if (this._width !== value) {
if (!value && value != 0) {
this.scale.x = 1;
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);
}
}
/**
* texture的高度和缩放乘积
* @member {number}
*/
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) {
if (this._height !== value) {
if (!value && value != 0) {
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);
}
}
/**
* 0,0标识左上角,0.5,0.5表示中间,1,1表示右下角
......
......@@ -559,7 +559,7 @@ export class Stage extends Container {
* @return {{w: number, h: number}}
*/
public getRootDivWH(div: HTMLDivElement) {
let sw = div.style.width;
/*let sw = div.style.width;
let sh = div.style.height;
let iw = document.body.clientWidth;
// let ih = document.body.clientHeight-40;
......@@ -580,7 +580,11 @@ export class Stage extends Container {
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 {
// private _textHeight: number = 0;
get width(): number {
if (this._width) return this._width;
if (!this._width && this._width != 0) {
this.updateText();
return this.scale.x * this.getLocalBounds().width;
} else {
return this._width;
}
}
set width(value: number) {
if (this._width !== value) {
if (!value && value != 0) {
this._width = undefined;
} else {
this._width = value;
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
}
}
get height(): number {
if (this._height) return this._height;
if (!this._height && this._height != 0) {
this.updateText();
return this.scale.y * this.getLocalBounds().height;
} else {
return this._height;
}
}
set height(value: number) {
if (this._height !== value) {
if (!value && value != 0) {
this._height = undefined;
} else {
this._height = value;
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
}
......@@ -691,7 +705,7 @@ export class TextField extends Sprite {
s.realLines = realLines;
s._prepContext(ctx);
let textWidth = s._width;
let textWidth = !s._width && s._width != 0 ? 0 : s._width;
// let lineH = s._lineSpacing + s.size;
//单行文本时
if (isPureText && text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
......@@ -719,7 +733,7 @@ export class TextField extends Sprite {
}
} else {
//textWidth取每行最大值,如果没设置过textWidth
const shouldMeasureTextWidth = !textWidth;
const shouldMeasureTextWidth = !s._width && s._width != 0 ? true : false;
let index = 0;
for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i];
......@@ -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属性
* 不考虑trim,
......
This diff is collapsed.
......@@ -4,6 +4,8 @@
import {DisplayObject} from "../../2d/display/index";
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";
export class StackContainer extends Node {
private _mutex: boolean;
private _stack = [];
private _inserted = 0;
constructor(mutex = true) {
private _playing = false;
private _actionQueue = [];
constructor(mutex = true, inserted = 0) {
super();
this._mutex = mutex;
this._inserted = inserted;
this.percentWidth = 100;
this.percentHeight = 100;
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 options
* @param dispatch
* @param playEffect
*/
push(view: DisplayObject, options?, dispatch = true) {
if (this._mutex && this.children.length > 0) {
this._stack.push(this.removeChildAt(0));
push(view: DisplayObject, options?, playEffect = true) {
this._actionQueue.push({action: 'push', args: arguments});
this._playNextAction();
}
this.addChild(view);
if (dispatch) {
this.dispatchEvent('change', {action: 'push', view, options});
}
/**
* 撤出视图
* @param options
* @param playEffect
*/
pop(options?, playEffect = true) {
this._actionQueue.push({action: 'pop', args: arguments});
this._playNextAction();
}
/**
* 替换顶层视图
* @param view
* @param options
* @param playEffect
*/
replace(view: DisplayObject, options?) {
if (this.pop(false)) {
this.push(view, options, false);
this.dispatchEvent('change', {action: 'replace', view, options});
}
replace(view: DisplayObject, options?, playEffect = true) {
this._actionQueue.push({action: 'replace', args: arguments});
this._playNextAction();
}
/**
* 撤出视图
* 撤出全部视图
* @param view
* @param options
* @param playEffect
*/
pop(dispatch = true) {
let len = this.children.length;
popAll(view?: DisplayObject, options?, playEffect = true) {
this._actionQueue.push({action: 'popAll', args: arguments});
this._playNextAction();
}
private _playNextAction = () => {
if (this._playing || this._actionQueue.length === 0) {
return;
}
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._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;
}
this.removeChildAt(len - 1);
let lastView = this.getChildAt(this.children.length - 1);
let view;
if (this._mutex) {
this.addChild(this._stack.pop());
view = this._stack.pop();
view.visible = false;
this.addChild(view);
}
if (dispatch) {
this.dispatchEvent('change', {action: 'pop'});
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();
}
return true;
)
})
}
/**
* 撤出全部视图
* @param view
* @param options
*/
popAll(view?: DisplayObject, options?) {
this.removeChildren();
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) {
this.push(view, options, false);
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();
}
this.dispatchEvent('change', {action: 'popAll', view, options});
)
})
}
}
\ No newline at end of file
......@@ -3,8 +3,9 @@
*/
import {globalLoader} from "../../2d/loader/Loader";
import {arrayFind, linkScheme} from "../utils";
import {arrayFind, linkScheme} from "../utils/index";
import {parse} from "./bmp-text-manager";
import {globalEvent} from "../decorators/events";
let assetsConfig = [];
......@@ -22,10 +23,89 @@ const loaderMapping = {
'': '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?) {
if (!config) {
console.log();
}
let total = config.length;
let loaded = 0;
let failedList = [];
......@@ -33,14 +113,16 @@ export function loadAssets(config, onProgress?, onComplete?) {
return Promise.all(
config.map(assetConfig => {
assetsConfig.push(assetConfig);
if (assetConfig.url.indexOf(linkScheme) === 0) {
let linkUUID = assetConfig.url.replace(linkScheme, '');
assetConfig = getAssetByUUID(linkUUID);
}
if (assetConfig) {
const {url, ext, uuid} = assetConfig;
const loadFunc = loaderMapping[ext];
if (loadFunc) {
if(url.indexOf(linkScheme) === 0){
loaded++;
onProgress && onProgress(loaded, total);
return Promise.resolve();
}
let method = globalLoader['load' + loadFunc];
return method.call(globalLoader, url, uuid).then(
(data) => {
......@@ -54,6 +136,13 @@ export function loadAssets(config, onProgress?, onComplete?) {
}
);
} else {
return p();
}
} else {
return p();
}
function p() {
loaded++;
onProgress && onProgress(loaded, total);
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() {
}
}
export function accessLog(pagebizid, params?) {
export function accessLog(pageBizId, params?) {
let p = {
pagebizid,
pageBizId,
};
injectProp(p, params);
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