mapcomplete/UI/Base/Combine.ts

32 lines
892 B
TypeScript
Raw Permalink Normal View History

2020-07-21 01:37:48 +02:00
import {UIElement} from "../UIElement";
2020-09-12 23:15:17 +02:00
import {FixedUiElement} from "./FixedUiElement";
import {Utils} from "../../Utils";
2020-07-21 01:37:48 +02:00
export default class Combine extends UIElement {
2020-09-12 23:15:17 +02:00
private readonly uiElements: UIElement[];
2020-07-21 01:37:48 +02:00
2020-09-12 23:15:17 +02:00
constructor(uiElements: (string | UIElement)[]) {
super();
this.uiElements = Utils.NoNull(uiElements)
.map(el => {
if (typeof el === "string") {
return new FixedUiElement(el);
}
return el;
});
2020-07-21 01:37:48 +02:00
}
InnerRender(): string {
return this.uiElements.map(ui => {
if(ui === undefined || ui === null){
return "";
}
if(ui.Render === undefined){
console.error("Not a UI-element", ui);
return "";
}
return ui.Render();
}).join("");
2020-07-21 01:37:48 +02:00
}
2020-07-21 01:37:48 +02:00
}