mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 12:49:25 +08:00
fix: appendChild时没有removeChild
This commit is contained in:
parent
d98bae7144
commit
f9358eb24e
@ -13,7 +13,7 @@ export class Container<E extends EContainerEvent = EContainerEvent>
|
|||||||
extends RenderItem<E | EContainerEvent>
|
extends RenderItem<E | EContainerEvent>
|
||||||
implements IRenderChildable
|
implements IRenderChildable
|
||||||
{
|
{
|
||||||
children: RenderItem[] = [];
|
children: Set<RenderItem> = new Set();
|
||||||
sortedChildren: RenderItem[] = [];
|
sortedChildren: RenderItem[] = [];
|
||||||
|
|
||||||
private needSort: boolean = false;
|
private needSort: boolean = false;
|
||||||
@ -46,13 +46,7 @@ export class Container<E extends EContainerEvent = EContainerEvent>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private requestSort() {
|
||||||
* 添加子元素到这个容器上,然后在下一个tick执行更新
|
|
||||||
* @param children 要添加的子元素
|
|
||||||
*/
|
|
||||||
appendChild(...children: RenderItem<any>[]) {
|
|
||||||
children.forEach(v => (v.parent = this));
|
|
||||||
this.children.push(...children);
|
|
||||||
if (!this.needSort) {
|
if (!this.needSort) {
|
||||||
this.needSort = true;
|
this.needSort = true;
|
||||||
this.requestBeforeFrame(() => {
|
this.requestBeforeFrame(() => {
|
||||||
@ -60,23 +54,38 @@ export class Container<E extends EContainerEvent = EContainerEvent>
|
|||||||
this.sortChildren();
|
this.sortChildren();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加子元素到这个容器上,然后在下一个tick执行更新
|
||||||
|
* @param children 要添加的子元素
|
||||||
|
*/
|
||||||
|
appendChild(...children: RenderItem<any>[]) {
|
||||||
|
children.forEach(v => {
|
||||||
|
v.remove();
|
||||||
|
this.children.add(v);
|
||||||
|
v.parent = this;
|
||||||
|
});
|
||||||
|
children.forEach(v => (v.parent = this));
|
||||||
|
this.requestSort();
|
||||||
this.update(this);
|
this.update(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeChild(...child: RenderItem<any>[]): void {
|
removeChild(...child: RenderItem<any>[]): void {
|
||||||
|
let changed = false;
|
||||||
child.forEach(v => {
|
child.forEach(v => {
|
||||||
const index = this.children.indexOf(v);
|
const success = this.children.delete(v);
|
||||||
if (index === -1) return;
|
if (success) changed = true;
|
||||||
this.children.splice(index, 1);
|
v.parent = void 0;
|
||||||
});
|
});
|
||||||
this.sortChildren();
|
if (changed) this.requestSort();
|
||||||
this.update(this);
|
this.update(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortChildren() {
|
sortChildren() {
|
||||||
this.sortedChildren = this.children
|
this.sortedChildren = [...this.children].sort(
|
||||||
.slice()
|
(a, b) => a.zIndex - b.zIndex
|
||||||
.sort((a, b) => a.zIndex - b.zIndex);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy(): void {
|
destroy(): void {
|
||||||
|
@ -52,7 +52,7 @@ interface IRenderConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IRenderChildable {
|
export interface IRenderChildable {
|
||||||
children: RenderItem[];
|
children: Set<RenderItem>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向这个元素添加子元素
|
* 向这个元素添加子元素
|
||||||
@ -407,7 +407,6 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
|||||||
*/
|
*/
|
||||||
remove() {
|
remove() {
|
||||||
this.parent?.removeChild(this);
|
this.parent?.removeChild(this);
|
||||||
this.parent = void 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -813,16 +813,14 @@ class ShaderProgram {
|
|||||||
/**
|
/**
|
||||||
* 获取一个 uniform matrix,需要事先定义,否则返回null
|
* 获取一个 uniform matrix,需要事先定义,否则返回null
|
||||||
* @param matrix uniform matrix 的名称
|
* @param matrix uniform matrix 的名称
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
getMatrix(matrix: string): ShaderUniformMatrix | null {
|
getMatrix(matrix: string): ShaderUniformMatrix | null {
|
||||||
return this.matrix.get(matrix) ?? null;
|
return this.matrix.get(matrix) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取一个 uniform block,例如 UBO VAO VBO,需要事先定义,否则返回null
|
* 获取一个 uniform block,例如 UBO,需要事先定义,否则返回null
|
||||||
* @param block uniform block 的名称
|
* @param block uniform block 的名称
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
getUniformBlock(block: string): ShaderUniformBlock | null {
|
getUniformBlock(block: string): ShaderUniformBlock | null {
|
||||||
return this.block.get(block) ?? null;
|
return this.block.get(block) ?? null;
|
||||||
@ -923,7 +921,7 @@ class ShaderProgram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定义一个 uniform block,例如 UBO VAO VBO,并存入本着色器程序的 uniform block 映射
|
* 定义一个 uniform block,例如 UBO,并存入本着色器程序的 uniform block 映射
|
||||||
* 用于一次性向着色器传输大量数据
|
* 用于一次性向着色器传输大量数据
|
||||||
* @param uniform uniform block 名称
|
* @param uniform uniform block 名称
|
||||||
* @returns uniform block 的操作对象,可用于设置其值
|
* @returns uniform block 的操作对象,可用于设置其值
|
||||||
|
Loading…
Reference in New Issue
Block a user