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>
|
||||
implements IRenderChildable
|
||||
{
|
||||
children: RenderItem[] = [];
|
||||
children: Set<RenderItem> = new Set();
|
||||
sortedChildren: RenderItem[] = [];
|
||||
|
||||
private needSort: boolean = false;
|
||||
@ -46,13 +46,7 @@ export class Container<E extends EContainerEvent = EContainerEvent>
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加子元素到这个容器上,然后在下一个tick执行更新
|
||||
* @param children 要添加的子元素
|
||||
*/
|
||||
appendChild(...children: RenderItem<any>[]) {
|
||||
children.forEach(v => (v.parent = this));
|
||||
this.children.push(...children);
|
||||
private requestSort() {
|
||||
if (!this.needSort) {
|
||||
this.needSort = true;
|
||||
this.requestBeforeFrame(() => {
|
||||
@ -60,23 +54,38 @@ export class Container<E extends EContainerEvent = EContainerEvent>
|
||||
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);
|
||||
}
|
||||
|
||||
removeChild(...child: RenderItem<any>[]): void {
|
||||
let changed = false;
|
||||
child.forEach(v => {
|
||||
const index = this.children.indexOf(v);
|
||||
if (index === -1) return;
|
||||
this.children.splice(index, 1);
|
||||
const success = this.children.delete(v);
|
||||
if (success) changed = true;
|
||||
v.parent = void 0;
|
||||
});
|
||||
this.sortChildren();
|
||||
if (changed) this.requestSort();
|
||||
this.update(this);
|
||||
}
|
||||
|
||||
sortChildren() {
|
||||
this.sortedChildren = this.children
|
||||
.slice()
|
||||
.sort((a, b) => a.zIndex - b.zIndex);
|
||||
this.sortedChildren = [...this.children].sort(
|
||||
(a, b) => a.zIndex - b.zIndex
|
||||
);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
|
@ -52,7 +52,7 @@ interface IRenderConfig {
|
||||
}
|
||||
|
||||
export interface IRenderChildable {
|
||||
children: RenderItem[];
|
||||
children: Set<RenderItem>;
|
||||
|
||||
/**
|
||||
* 向这个元素添加子元素
|
||||
@ -407,7 +407,6 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
||||
*/
|
||||
remove() {
|
||||
this.parent?.removeChild(this);
|
||||
this.parent = void 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -813,16 +813,14 @@ class ShaderProgram {
|
||||
/**
|
||||
* 获取一个 uniform matrix,需要事先定义,否则返回null
|
||||
* @param matrix uniform matrix 的名称
|
||||
* @returns
|
||||
*/
|
||||
getMatrix(matrix: string): ShaderUniformMatrix | null {
|
||||
return this.matrix.get(matrix) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个 uniform block,例如 UBO VAO VBO,需要事先定义,否则返回null
|
||||
* 获取一个 uniform block,例如 UBO,需要事先定义,否则返回null
|
||||
* @param block uniform block 的名称
|
||||
* @returns
|
||||
*/
|
||||
getUniformBlock(block: string): ShaderUniformBlock | 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 名称
|
||||
* @returns uniform block 的操作对象,可用于设置其值
|
||||
|
Loading…
Reference in New Issue
Block a user