2019-07-03 02:56:33 +08:00
|
|
|
import React, { ReactNode, Component } from "react";
|
2019-07-03 00:08:06 +08:00
|
|
|
import { Area, Quest } from "../../domain";
|
|
|
|
import { get_quest_renderer } from "../../rendering/QuestRenderer";
|
2019-05-29 00:40:29 +08:00
|
|
|
|
2019-07-01 01:55:30 +08:00
|
|
|
type Props = {
|
2019-07-03 00:08:06 +08:00
|
|
|
quest?: Quest;
|
|
|
|
area?: Area;
|
|
|
|
};
|
2019-05-29 00:40:29 +08:00
|
|
|
|
2019-07-03 02:56:33 +08:00
|
|
|
export class RendererComponent extends Component<Props> {
|
2019-07-01 01:55:30 +08:00
|
|
|
private renderer = get_quest_renderer();
|
2019-05-29 00:40:29 +08:00
|
|
|
|
2019-07-03 02:56:33 +08:00
|
|
|
render(): ReactNode {
|
2019-07-03 00:08:06 +08:00
|
|
|
return <div style={{ overflow: "hidden" }} ref={this.modifyDom} />;
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
2019-07-03 02:56:33 +08:00
|
|
|
componentDidMount(): void {
|
2019-07-03 00:08:06 +08:00
|
|
|
window.addEventListener("resize", this.onResize);
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
2019-07-03 02:56:33 +08:00
|
|
|
componentWillUnmount(): void {
|
2019-07-03 00:08:06 +08:00
|
|
|
window.removeEventListener("resize", this.onResize);
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
2019-07-03 02:56:33 +08:00
|
|
|
componentWillReceiveProps({ quest, area }: Props): void {
|
2019-07-01 01:55:30 +08:00
|
|
|
this.renderer.set_quest_and_area(quest, area);
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
2019-07-03 02:56:33 +08:00
|
|
|
shouldComponentUpdate(): boolean {
|
2019-05-29 00:40:29 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-30 23:57:31 +08:00
|
|
|
private modifyDom = (div: HTMLDivElement | null) => {
|
|
|
|
if (div) {
|
2019-07-01 01:55:30 +08:00
|
|
|
this.renderer.set_size(div.clientWidth, div.clientHeight);
|
|
|
|
div.appendChild(this.renderer.dom_element);
|
2019-05-30 23:57:31 +08:00
|
|
|
}
|
2019-07-03 00:08:06 +08:00
|
|
|
};
|
2019-05-29 00:40:29 +08:00
|
|
|
|
2019-05-29 20:46:29 +08:00
|
|
|
private onResize = () => {
|
2019-07-02 23:00:24 +08:00
|
|
|
const wrapper_div = this.renderer.dom_element.parentNode as HTMLDivElement;
|
|
|
|
this.renderer.set_size(wrapper_div.clientWidth, wrapper_div.clientHeight);
|
2019-07-03 00:08:06 +08:00
|
|
|
};
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|