Commit 20a02e96 authored by rockyl's avatar rockyl

修复scale找不到的问题

parent d6398ae8
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
"rollup-plugin-progress": "^1.1.2" "rollup-plugin-progress": "^1.1.2"
}, },
"devDependencies": { "devDependencies": {
"dts-bundle": "^0.7.3",
"dts-bundle-generator": "^4.3.0", "dts-bundle-generator": "^4.3.0",
"glob": "^7.1.6", "glob": "^7.1.6",
"rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-commonjs": "^10.1.0",
...@@ -22,7 +21,6 @@ ...@@ -22,7 +21,6 @@
"typescript": "^2.7.2" "typescript": "^2.7.2"
}, },
"scripts": { "scripts": {
"declare": "node scripts/declare.js src/index.ts",
"dev": "rollup -c -m -w", "dev": "rollup -c -m -w",
"build": "rollup -c -o dist/engine.js", "build": "rollup -c -o dist/engine.js",
"build:prod": "rollup -c -o dist/engine.min.js --environment BUILD:production", "build:prod": "rollup -c -o dist/engine.min.js --environment BUILD:production",
......
...@@ -510,6 +510,9 @@ export class DisplayObject extends EventDispatcher { ...@@ -510,6 +510,9 @@ export class DisplayObject extends EventDispatcher {
* @member {Point|ObservablePoint} * @member {Point|ObservablePoint}
*/ */
get scale() { get scale() {
if(this.destroyed){
return 1;
}
return this.transform.scale; return this.transform.scale;
} }
......
import { ALIGN_MODE, AUTO_SIZE_MODE } from "./auto-adjust"; import {ALIGN_MODE, AUTO_SIZE_MODE} from "./auto-adjust";
import { toBoolean } from "../utils/utils"; import {toBoolean} from "../utils/utils";
import { Container } from "../../2d/display/index"; import {Container} from "../../2d/display/index";
/** /**
* 自适应管理器 * 自适应管理器
...@@ -8,241 +8,247 @@ import { Container } from "../../2d/display/index"; ...@@ -8,241 +8,247 @@ import { Container } from "../../2d/display/index";
*/ */
class AlignManager { class AlignManager {
// 这个列表里的对象会在渲染前被自动调整 // 这个列表里的对象会在渲染前被自动调整
private alignList = []; private alignList = [];
constructor() {
}
/**
* flash (渲染前)
*/
public flush() {
constructor() { const list = this.alignList;
} list.forEach((v: Container) => {
if(v.destroyed){
return;
}
this.autoSize(v); // 去调整大小
this.align(v); // 去自动对齐
});
/** // 要在这里单独检查,因为对齐一次后可能遇到其父节点需要对齐导致其再对齐一次
* flash (渲染前) list.forEach((v) => {
*/ if(v.destroyed){
public flush() { return;
}
if (v.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
v.alignEnabled = false;
}
});
// 干掉列表
list.length = 0;
}
const list = this.alignList; /**
* align
* @param that
*/
private align(that) {
list.forEach((v: Container) => { if (!that.alignEnabled) return; // 如果的自动对齐关闭里则啥也不干
this.autoSize(v); // 去调整大小
this.align(v); // 去自动对齐
});
// 要在这里单独检查,因为对齐一次后可能遇到其父节点需要对齐导致其再对齐一次 // if(that.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
list.forEach((v) => { // that.alignEnabled = false;
if (v.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它 // }
v.alignEnabled = false;
}
});
// 干掉列表
list.length = 0;
}
/** const {
* align percentWidth, percentHeight,
* @param that top, bottom, left, right,
*/ percentTop, percentBottom, percentLeft, percentRight,
private align(that) { horizonCenter, verticalCenter
} = that;
if (!that.alignEnabled) return; // 如果的自动对齐关闭里则啥也不干 let {_width: tW_Z = 0, _height: tH_Z = 0} = that;
// if(that.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它 const {_width: pW_Z = 0, _height: pH_Z = 0} = (that.parent || {});
// that.alignEnabled = false;
// } /// TODO null / 100 == 0 ?????? wtf!!!! 我裂开了
// percentWidth /= 100;
const { // percentHeight /= 100;
percentWidth, percentHeight,
top, bottom, left, right, // percentTop /= 100;
percentTop, percentBottom, percentLeft, percentRight, // percentBottom /= 100;
horizonCenter, verticalCenter // percentLeft /= 100;
} = that; // percentRight /= 100;
let {_width: tW_Z = 0, _height: tH_Z = 0} = that; const judgePL = toBoolean(percentLeft)
, judgePR = toBoolean(percentRight)
const {_width: pW_Z = 0, _height: pH_Z = 0} = (that.parent || {}); , judgePT = toBoolean(percentTop)
, judgePB = toBoolean(percentBottom);
/// TODO null / 100 == 0 ?????? wtf!!!! 我裂开了
// percentWidth /= 100; // 先转化一下
// percentHeight /= 100; const _left = judgePL ? percentLeft / 100 * pW_Z : left
, _right = judgePR ? percentRight / 100 * pW_Z : right
// percentTop /= 100; , _top = judgePT ? percentTop / 100 * pH_Z : top
// percentBottom /= 100; , _bottom = judgePB ? percentBottom / 100 * pH_Z : bottom;
// percentLeft /= 100;
// percentRight /= 100; /**
* 计算 width 和 x 值
const judgePL = toBoolean(percentLeft) */
, judgePR = toBoolean(percentRight) if (toBoolean(_left) && toBoolean(_right)) { // _left _right 都有则直接拉伸或缩小
, judgePT = toBoolean(percentTop)
, judgePB = toBoolean(percentBottom); that.x = _left;
// 先转化一下 that.width = pW_Z - _left - _right;
const _left = judgePL ? percentLeft / 100 * pW_Z : left
, _right = judgePR ? percentRight / 100 * pW_Z : right } else {
, _top = judgePT ? percentTop / 100 * pH_Z : top // 先设置下自己的 width
, _bottom = judgePB ? percentBottom / 100 * pH_Z : bottom; if (toBoolean(percentWidth)) {
tW_Z = that.width = pW_Z * percentWidth / 100
/** } else {
* 计算 width 和 x 值 tW_Z = that.width;
*/ }
if (toBoolean(_left) && toBoolean(_right)) { // _left _right 都有则直接拉伸或缩小
// 先考虑 horizonCenter 属性
that.x = _left; if (toBoolean(horizonCenter)) {
// x 值 = 父节点的中间值 - 自己宽度的一半 - 居中差值
that.width = pW_Z - _left - _right; that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter;
} else { } else if (toBoolean(_left)) { // 假如有 _left
// 先设置下自己的 width
if(toBoolean(percentWidth)){ that.x = _left;
tW_Z = that.width = pW_Z * percentWidth / 100
}else{ } else if (toBoolean(_right)) { // 假如有 _right
tW_Z = that.width;
} that.x = pW_Z - _right - tW_Z;
// 先考虑 horizonCenter 属性 }
if (toBoolean(horizonCenter)) { }
// x 值 = 父节点的中间值 - 自己宽度的一半 - 居中差值
that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter; /**
* 计算 height 和 y 值
} else if (toBoolean(_left)) { // 假如有 _left */
if (toBoolean(_top) && toBoolean(_bottom)) { // _top _bottom 都有则直接拉伸或缩小
that.x = _left;
that.y = _top;
} else if (toBoolean(_right)) { // 假如有 _right
that.height = pH_Z - _top - _bottom;
that.x = pW_Z - _right - tW_Z;
} else {
} // 先设置下自己的 height
} if (toBoolean(percentHeight)) {
tH_Z = that.height = pH_Z * percentHeight / 100
/** } else {
* 计算 height 和 y 值 tH_Z = that.height;
*/ }
if (toBoolean(_top) && toBoolean(_bottom)) { // _top _bottom 都有则直接拉伸或缩小
// 先考虑 horizonCenter 属性
that.y = _top; if (toBoolean(verticalCenter)) {
// x 值 = 父节点的中间值 - 自己高度的一半 - 居中差值
that.height = pH_Z - _top - _bottom; that.y = pH_Z / 2 - tH_Z / 2 + verticalCenter;
} else { } else if (toBoolean(_top)) { // 假如有 _top
// 先设置下自己的 height
if(toBoolean(percentHeight)){ that.y = _top;
tH_Z = that.height = pH_Z * percentHeight / 100
}else{ } else if (toBoolean(_bottom)) { // 假如有 _bottom
tH_Z = that.height;
} that.y = pH_Z - _bottom - tH_Z;
// 先考虑 horizonCenter 属性 }
if (toBoolean(verticalCenter)) { }
// x 值 = 父节点的中间值 - 自己高度的一半 - 居中差值 if (that.children) {
that.y = pH_Z / 2 - tH_Z / 2 + verticalCenter; that.children.forEach(v => this.align(v));
}
} else if (toBoolean(_top)) { // 假如有 _top }
that.y = _top; /**
* 自动大小
} else if (toBoolean(_bottom)) { // 假如有 _bottom * @param that
*/
that.y = pH_Z - _bottom - tH_Z; private autoSize(that) {
if (!that.children) {
} return;
} }
if(that.children){ const len = that.children.length
that.children.forEach(v => this.align(v)); if (len > 0) {
}
} // 检测本身的是否是可以自动宽
// if (that.autoWidth
/** if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
* 自动大小 || that.autoSizeMode === AUTO_SIZE_MODE.WIDTH
* @param that // && !toBoolean(that.right) /// TODO 我把它注释了 注释这行可以让容器设置了 right 后反向撑开,保持 right 边距不变
*/ && !toBoolean(that.percentWidth)) {
private autoSize(that) {
if(!that.children){ /// TODO 下面这段注释的代码可以实现让其左边撑开,不过还有未知bug
return; // 找出子节点最小x
} // let minX = 0;
const len = that.children.length // for(let i = 0; i < len; i++) {
if (len > 0) { // if(that.children[i].x < minX) {
// minX = that.children[i].x;
// 检测本身的是否是可以自动宽 // }
// if (that.autoWidth // }
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL // if(minX < 0) {
|| that.autoSizeMode === AUTO_SIZE_MODE.WIDTH // that.children.forEach(v => v.x -= minX);
// && !toBoolean(that.right) /// TODO 我把它注释了 注释这行可以让容器设置了 right 后反向撑开,保持 right 边距不变 // that.x += minX;
&& !toBoolean(that.percentWidth)) { // that.width -= minX;
// }
/// TODO 下面这段注释的代码可以实现让其左边撑开,不过还有未知bug
// 找出子节点最小x // 找出最右值
// let minX = 0; let maxR = 0;
// for(let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
// if(that.children[i].x < minX) { if (toBoolean(that.children[i].right)) continue; /// TODO 开启这个,忽略带 right 值的子节点
// minX = that.children[i].x; let _x = that.children[i].x || 0;
// } let _w = that.children[i].__width || 0;
// } (_x + _w > maxR) ? maxR = _x + _w : 0;
// if(minX < 0) { }
// that.children.forEach(v => v.x -= minX); that.width = maxR;
// that.x += minX; }
// that.width -= minX;
// } // 检测本身的是否是可以自动高
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
// 找出最右值 || that.autoSizeMode === AUTO_SIZE_MODE.HEIGHT
let maxR = 0; // && !toBoolean(that.bottom) /// TODO 我把它注释了 注释这行可以让容器设置了 bottom 后反向撑开,保持 bottom 边距不变
for (let i = 0; i < len; i++) { && !toBoolean(that.percentHeight)) {
if (toBoolean(that.children[i].right)) continue; /// TODO 开启这个,忽略带 right 值的子节点
let _x = that.children[i].x || 0; /// TODO 下面这段注释的代码可以实现让其上边撑开,不过还有未知bug
let _w = that.children[i].__width || 0; // 找出子节点最小y
(_x + _w > maxR) ? maxR = _x + _w : 0; // let minY = 0;
} // for(let i = 1; i < len; i++) {
that.width = maxR; // if(that.children[i].y < minY) {
} // minY = that.children[i].y;
// }
// 检测本身的是否是可以自动高 // }
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL // if(minY < 0) {
|| that.autoSizeMode === AUTO_SIZE_MODE.HEIGHT // that.children.forEach(v => v.y -= minY);
// && !toBoolean(that.bottom) /// TODO 我把它注释了 注释这行可以让容器设置了 bottom 后反向撑开,保持 bottom 边距不变 // that.y += minY;
&& !toBoolean(that.percentHeight)) { // that.height -= minY;
// }
/// TODO 下面这段注释的代码可以实现让其上边撑开,不过还有未知bug
// 找出子节点最小y // 找出最下值
// let minY = 0; let maxB = 0;
// for(let i = 1; i < len; i++) { for (let i = 0; i < len; i++) {
// if(that.children[i].y < minY) { if (toBoolean(that.children[i].bottom)) continue; /// TODO 开启这个,忽略带 bottom 值的子节点
// minY = that.children[i].y; let _y = that.children[i].y || 0;
// } let _h = that.children[i].__height || 0;
// } (_y + _h > maxB) ? maxB = _y + _h : 0;
// if(minY < 0) { }
// that.children.forEach(v => v.y -= minY); that.height = maxB;
// that.y += minY; }
// that.height -= minY; }
// } }
// 找出最下值 /**
let maxB = 0; * 添加一个变脏的对象
for (let i = 0; i < len; i++) { * @param obj
if (toBoolean(that.children[i].bottom)) continue; /// TODO 开启这个,忽略带 bottom 值的子节点 */
let _y = that.children[i].y || 0; public addAlign(obj) {
let _h = that.children[i].__height || 0; const list = this.alignList;
(_y + _h > maxB) ? maxB = _y + _h : 0; if (list.indexOf(obj) < 0) {
} list.push(obj);
that.height = maxB; }
} }
}
}
/**
* 添加一个变脏的对象
* @param obj
*/
public addAlign(obj) {
const list = this.alignList;
if (list.indexOf(obj) < 0) {
list.push(obj);
}
}
} }
function tt(...v) { function tt(...v) {
for (let i = 0; i < v.length; i++) { for (let i = 0; i < v.length; i++) {
if (!toBoolean(v[i])) return false; if (!toBoolean(v[i])) return false;
} }
return true; return true;
} }
export let alignMgr = new AlignManager(); export let alignMgr = new AlignManager();
...@@ -151,7 +151,6 @@ export class GameStage extends Node { ...@@ -151,7 +151,6 @@ export class GameStage extends Node {
start() { start() {
const {options: {entrySceneView,},} = this._config; const {options: {entrySceneView,},} = this._config;
setTimeout(async () => { setTimeout(async () => {
let sceneEntry = await this.instantiateView(entrySceneView); let sceneEntry = await this.instantiateView(entrySceneView);
if (sceneEntry) { if (sceneEntry) {
......
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