import * as React from "react"; import { GlobalState } from '../../globalState'; import { Nullable } from 'babylonjs/types'; import { DefaultNodeModel } from '../../components/diagram/defaultNodeModel'; import { ButtonLineComponent } from '../../sharedComponents/buttonLineComponent'; import { LineContainerComponent } from '../../sharedComponents/lineContainerComponent'; import { StringTools } from '../../stringTools'; import { FileButtonLineComponent } from '../../sharedComponents/fileButtonLineComponent'; import { Tools } from 'babylonjs/Misc/tools'; import { INodeLocationInfo } from '../../nodeLocationInfo'; require("./propertyTab.scss"); interface IPropertyTabComponentProps { globalState: GlobalState; } export class PropertyTabComponent extends React.Component }> { constructor(props: IPropertyTabComponentProps) { super(props) this.state = { currentNode: null }; } componentWillMount() { this.props.globalState.onSelectionChangedObservable.add(block => { this.setState({ currentNode: block }); }); } load(file: File) { Tools.ReadFile(file, (data) => { let decoder = new TextDecoder("utf-8"); let serializationObject = JSON.parse(decoder.decode(data)); this.props.globalState.nodeMaterial!.loadFromSerialization(serializationObject, ""); // Check for id mapping if (serializationObject.locations && serializationObject.map) { let map: {[key: number]: number} = serializationObject.map; let locations: INodeLocationInfo[] = serializationObject.locations; for (var location of locations) { location.blockId = map[location.blockId]; } } this.props.globalState.onResetRequiredObservable.notifyObservers(serializationObject.locations); }, undefined, true); } save() { let material = this.props.globalState.nodeMaterial; let serializationObject = material.serialize(); // Store node locations for (var block of material.attachedBlocks) { let node = this.props.globalState.onGetNodeFromBlock(block); if (!serializationObject.locations) { serializationObject.locations = []; } serializationObject.locations.push({ blockId: block.uniqueId, x: node ? node.x : 0, y: node ? node.y : 0 }); } // Output let json = JSON.stringify(serializationObject, undefined, 2); StringTools.DownloadAsFile(this.props.globalState.hostDocument, json, "nodeMaterial.json"); } render() { if (this.state.currentNode) { return (
{this.state.currentNode.renderProperties(this.props.globalState)}
); } return (
{ this.props.globalState.nodeMaterial!.setToDefault(); this.props.globalState.onResetRequiredObservable.notifyObservers(null); }} /> { this.props.globalState.onZoomToFitRequiredObservable.notifyObservers(); }} /> { this.props.globalState.onReOrganizedRequiredObservable.notifyObservers(); }} /> this.load(file)} accept=".json" /> { this.save(); }} /> { StringTools.DownloadAsFile(this.props.globalState.hostDocument, this.props.globalState.nodeMaterial!.generateCode(), "code.txt"); }} /> { StringTools.DownloadAsFile(this.props.globalState.hostDocument, this.props.globalState.nodeMaterial!.compiledShaders, "shaders.txt"); }} />
); } }