From 5dd3388566c73729309f50acd96fe8bf5d5aa8ba Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Fri, 8 Jun 2018 17:41:09 -0700 Subject: [PATCH] Thread through name and position updates --- src/components/StringInput.js | 10 ++++- src/components/Vector3Input.js | 6 +-- src/containers/NodePropertyGroupContainer.js | 40 ++++++++++++++++++-- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/components/StringInput.js b/src/components/StringInput.js index 29ad64f7..6f855106 100644 --- a/src/components/StringInput.js +++ b/src/components/StringInput.js @@ -1,6 +1,12 @@ import React from "react"; +import PropTypes from "prop-types"; import styles from "./StringInput.scss"; -export default function StringInput(props) { - return ; +export default function StringInput({ value, onChange }) { + return ; } + +StringInput.propTypes = { + value: PropTypes.string, + onChange: PropTypes.func +}; diff --git a/src/components/Vector3Input.js b/src/components/Vector3Input.js index b9e735c1..f71ed259 100644 --- a/src/components/Vector3Input.js +++ b/src/components/Vector3Input.js @@ -7,11 +7,11 @@ export default function Vector3Input({ value, onChange, ...rest }) { return (
X:
- onChange("x", x)} {...rest} /> + onChange({ x, y: value.y, z: value.z })} {...rest} />
Y:
- onChange("y", y)} {...rest} /> + onChange({ x: value.y, y, z: value.z })} {...rest} />
Z:
- onChange("z", z)} {...rest} /> + onChange({ x: value.y, y: value.y, z })} {...rest} />
); } diff --git a/src/containers/NodePropertyGroupContainer.js b/src/containers/NodePropertyGroupContainer.js index 95ee374b..a474d852 100644 --- a/src/containers/NodePropertyGroupContainer.js +++ b/src/containers/NodePropertyGroupContainer.js @@ -1,18 +1,50 @@ import React, { Component } from "react"; +import THREE from "../vendor/three"; +import PropTypes from "prop-types"; +import { withEditor } from "./EditorContext"; import PropertyGroup from "../components/PropertyGroup"; import InputGroup from "../components/InputGroup"; import Vector3Input from "../components/Vector3Input"; import StringInput from "../components/StringInput"; +import SetValueCommand from "../editor/commands/SetValueCommand"; +import SetPositionCommand from "../editor/commands/SetPositionCommand"; -export default class NodePropertyGroupContainer extends Component { +class NodePropertyGroupContainer extends Component { + static propTypes = { + editor: PropTypes.object + }; + constructor(props) { + super(props); + this.props.editor.signals.objectSelected.add(this.updateNode); + this.props.editor.signals.objectChanged.add(this.updateStateFromNode); + this.state = { node: {} }; + } + updateNode = node => { + this.setState({ node }, () => this.updateStateFromNode(node)); + }; + updateStateFromNode = node => { + // Ignore objectChanged signals if they are for another node. + if (!this.state.node || this.state.node !== node) return; + this.setState({ + name: node.name + }); + }; + updateName = e => { + if (!this.state.node) return; + this.props.editor.execute(new SetValueCommand(this.state.node, "name", e.target.value)); + }; + updatePosition = newPosition => { + if (!this.state.node) return; + this.props.editor.execute(new SetPositionCommand(this.state.node, new THREE.Vector3().copy(newPosition))); + }; render() { return ( - + - + @@ -24,3 +56,5 @@ export default class NodePropertyGroupContainer extends Component { ); } } + +export default withEditor(NodePropertyGroupContainer);