2019-05-29 00:40:29 +08:00
|
|
|
import React from 'react';
|
2019-05-30 03:43:06 +08:00
|
|
|
import { Area, Quest } from '../../domain';
|
2019-07-01 01:55:30 +08:00
|
|
|
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 = {
|
|
|
|
quest?: Quest,
|
|
|
|
area?: Area,
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
2019-05-29 23:04:06 +08:00
|
|
|
export class RendererComponent extends React.Component<Props> {
|
2019-07-01 01:55:30 +08:00
|
|
|
private renderer = get_quest_renderer();
|
2019-05-29 00:40:29 +08:00
|
|
|
|
|
|
|
render() {
|
2019-05-29 20:46:29 +08:00
|
|
|
return <div style={{ overflow: 'hidden' }} ref={this.modifyDom} />;
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2019-05-29 20:46:29 +08:00
|
|
|
window.addEventListener('resize', this.onResize);
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2019-05-29 20:46:29 +08:00
|
|
|
window.removeEventListener('resize', this.onResize);
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
2019-07-01 01:55:30 +08:00
|
|
|
componentWillReceiveProps({ quest, area }: Props) {
|
|
|
|
this.renderer.set_quest_and_area(quest, area);
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate() {
|
|
|
|
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-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-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
}
|