45 lines
841 B
TypeScript
45 lines
841 B
TypeScript
// UE/UEArray.ts
|
|
|
|
import type { Integer } from '#root/UE/Integer.ts';
|
|
|
|
export class UEArray<T> extends Array<T> {
|
|
constructor(items?: T[]) {
|
|
super();
|
|
if (items) {
|
|
this.push(...items);
|
|
}
|
|
Object.setPrototypeOf(this, UEArray.prototype);
|
|
}
|
|
|
|
public SetArrayElem(
|
|
Index: Integer = 0,
|
|
Item: T,
|
|
SizeToFit: boolean = false
|
|
): void {
|
|
this[Index] = Item;
|
|
if (SizeToFit && Index >= this.length) {
|
|
this.length = Index + 1;
|
|
}
|
|
}
|
|
|
|
public Add(Item: T): Integer {
|
|
this.push(Item);
|
|
return this.length - 1;
|
|
}
|
|
|
|
public Get(Index: Integer): T {
|
|
return this[Index]!;
|
|
}
|
|
|
|
public RemoveIndex(Index: Integer): void {
|
|
this.splice(Index, 1);
|
|
}
|
|
|
|
public Remove(Item: T): void {
|
|
const index = this.indexOf(Item);
|
|
if (index !== -1) {
|
|
this.splice(index, 1);
|
|
}
|
|
}
|
|
}
|