mapcomplete/UI/Base/Combine.ts

32 lines
892 B
TypeScript
Raw Normal View History

2020-07-20 23:37:48 +00:00
import {UIElement} from "../UIElement";
2020-09-12 21:15:17 +00:00
import {FixedUiElement} from "./FixedUiElement";
import {Utils} from "../../Utils";
2020-07-20 23:37:48 +00:00
export default class Combine extends UIElement {
2020-09-12 21:15:17 +00:00
private readonly uiElements: UIElement[];
2020-07-20 23:37:48 +00:00
2020-09-12 21:15:17 +00: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-20 23:37:48 +00: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-20 23:37:48 +00:00
}
2020-07-20 23:37:48 +00:00
}