import { InputNumber } from "antd"; import { observer } from "mobx-react"; import React, { ReactNode, Component, PureComponent } from "react"; import { QuestNpc, QuestObject, QuestEntity } from "../../domain"; import "./EntityInfoComponent.css"; import { IReactionDisposer, autorun } from "mobx"; import { Vec3 } from "../../data_formats/vector"; export type Props = { entity?: QuestEntity; }; @observer export class EntityInfoComponent extends Component { render(): ReactNode { const entity = this.props.entity; if (entity) { const section_id = entity.section ? entity.section.id : entity.section_id; let name = null; if (entity instanceof QuestObject) { name = ( Object: {entity.type.name} ); } else if (entity instanceof QuestNpc) { name = ( NPC: {entity.type.name} ); } return (
{name}
Section: {section_id}
World position:
Section position:
); } else { return
; } } } type CoordProps = { entity: QuestEntity; position_type: "position" | "section_position"; coord: "x" | "y" | "z"; }; class CoordRow extends PureComponent { render(): ReactNode { return ( {this.props.coord.toUpperCase()}: ); } } class CoordInput extends Component { private disposer?: IReactionDisposer; state = { value: 0 }; componentDidMount(): void { this.start_observing(); } componentWillUnmount(): void { if (this.disposer) this.disposer(); } componentDidUpdate(prev_props: CoordProps): void { if (this.props.entity !== prev_props.entity) { this.start_observing(); } } render(): ReactNode { return ( ); } private start_observing() { if (this.disposer) this.disposer(); this.disposer = autorun( () => { this.setState({ value: this.props.entity[this.props.position_type][this.props.coord], }); }, { name: `${this.props.entity.type.code}.${this.props.position_type}.${this.props.coord} changed`, delay: 50, } ); } private changed = (value?: number) => { if (value != null) { const entity = this.props.entity; const pos_type = this.props.position_type; const pos = entity[pos_type].clone(); pos[this.props.coord] = value; entity[pos_type] = pos; } }; }