Skip to content
Snippets Groups Projects
Commit 3bb8fce6 authored by Maximilian Giller's avatar Maximilian Giller :squid:
Browse files

Implemented frozen force engine behaviour and made some components more...

Implemented frozen force engine behaviour and made some components more resilient against missing savepoints
parent 881df3cf
No related branches found
No related tags found
1 merge request!2Implemented editor in the react framework
Pipeline #56649 passed
......@@ -18,12 +18,16 @@ type stateTypes = {
};
export class Editor extends React.PureComponent<propTypes, stateTypes> {
private defaultWarmupTicks = 100;
private warmupTicks = 100;
constructor(props: propTypes) {
super(props);
this.loadGraph = this.loadGraph.bind(this);
this.loadSpace = this.loadSpace.bind(this);
this.handleNodeClick = this.handleNodeClick.bind(this);
this.onHistoryChange = this.onHistoryChange.bind(this);
this.handleEngineStop = this.handleEngineStop.bind(this);
// Set as new state
this.state = {
......@@ -60,6 +64,8 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
const newState = new State();
const newGraph = Graph.parse(data);
this.warmupTicks = this.defaultWarmupTicks; // Should only run for each newly initialized graph, but then never again
// Is valid and parsed successfully?
// TODO: Check doesn't work for some reason, always returns true, even tho it should be considered defined
// if (Editor.globalGraph == undefined) {
......@@ -155,6 +161,18 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
this.forceUpdate();
}
private handleEngineStop() {
// Only do something on first stop for each graph
if (this.warmupTicks <= 0) {
return;
}
this.warmupTicks = 0; // Only warm up once, so stop warming up after the first freeze
this.state.graph.storeCurrentData("Initial state", false);
this.forceUpdate();
}
render(): React.ReactNode {
// The id "ks-editor" indicates, that the javascript associated with this should automatically be executed
return (
......@@ -176,6 +194,9 @@ export class Editor extends React.PureComponent<propTypes, stateTypes> {
graphData={this.state.graph.data}
onNodeClick={this.handleNodeClick}
autoPauseRedraw={false}
cooldownTicks={0}
warmupTicks={this.warmupTicks}
onEngineStop={this.handleEngineStop}
/>
) : undefined}
</div>
......
......@@ -64,7 +64,8 @@ export class HistoryNavigator extends React.Component<propTypes> {
<select
onChange={this.handleSelectSavepoint}
value={
this.props.historyObject
this.props.historyObject &&
this.props.historyObject.currentSavePoint
? this.props.historyObject.currentSavePoint.id
: 0
}
......
......@@ -26,8 +26,6 @@ export class Graph extends ManagedData {
this.connectElementsToGraph(this.data);
this.prepareIds(data);
this.storeCurrentData("Initial state", false);
}
/**
......
......@@ -70,6 +70,10 @@ export default class ManagedData extends SerializableItem {
* Returns true, if data has unsaved changes.
*/
public hasUnsavedChanges(): boolean {
if (this.history[this.historyPosition] === undefined) {
return this.data !== undefined;
}
return this.history[this.historyPosition].id !== this.savedHistoryId;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment