31 lines
898 B
TypeScript
31 lines
898 B
TypeScript
import { observer } from "mobx-react-lite";
|
|
import { state } from "../state";
|
|
import { ObjectViewInternal } from "./ObjectViewInternal";
|
|
import { PlayerObjectView } from "./CharacterView";
|
|
|
|
export type GameObjectViewProps = {
|
|
object: ObjectInstance;
|
|
isPlayer: boolean;
|
|
isSceneEditor?: boolean;
|
|
}
|
|
|
|
export const GameObjectView = observer(function (props: GameObjectViewProps) {
|
|
const objectType = state.world.getObjectTypeById(props.object.typeId);
|
|
if (!objectType)
|
|
return null;
|
|
|
|
if (props.isPlayer)
|
|
return <PlayerObjectView object={props.object} objectType={objectType} />;
|
|
|
|
function handleClick(): void {
|
|
state.game?.emitEvent('objectClicked', { object: props.object });
|
|
}
|
|
|
|
return <ObjectViewInternal
|
|
{...props}
|
|
objectType={objectType}
|
|
onClick={handleClick}
|
|
isSceneEditor={props.isSceneEditor}
|
|
/>;
|
|
});
|