diff --git a/index.html b/index.html index 0fcb000..08672c0 100644 --- a/index.html +++ b/index.html @@ -215,9 +215,11 @@ - + - + + + diff --git a/js/components/state.js b/js/components/state.js index b41a4ab..d31b5c0 100644 --- a/js/components/state.js +++ b/js/components/state.js @@ -6,7 +6,7 @@ class State { this.y = y; this.mouseOffsetX = 0; this.mouseOffsetY = 0; - this.color = '#f0f'; + this.color = '#fff'; this.isActive = false; this.activeTime = 0; this.isAcceptState = false; diff --git a/js/export/export.js b/js/export/export.js index caad25b..d527472 100644 --- a/js/export/export.js +++ b/js/export/export.js @@ -58,6 +58,7 @@ function parseFromJson(json) { doc.states = doc.states.map(state => Object.assign(new State(0, 0), state)); doc.connections = doc.connections.map(connection => { + console.log(connection.type); switch(connection.type) { case 'Connection': connection = Object.assign(new Connection(null, null), connection); @@ -73,9 +74,10 @@ function parseFromJson(json) { break; case 'StartConnection': - connection = Object.assign(new StartConnection(null, {x: 0, y: 0}), connection); + connection = Object.assign(new StartConnection(), connection); connection.state = doc.states.find(state => state.id === connection.state); + console.log(connection.state); break; } diff --git a/js/menu.js b/js/menu.js index eb6b559..48c493b 100644 --- a/js/menu.js +++ b/js/menu.js @@ -86,6 +86,16 @@ modalImport.addFooterBtn('Laden', 'btn', () => { } }); +const modalSimulate = new tingle.modal({ + footer: true, +}); +modalSimulate.setContent('

Maschine simulieren

'); +modalSimulate.addFooterBtn('Simulation starten', 'btn', () => { + modalSimulate.close(); + const input = document.getElementById('simulationInput').value; + simulate(input); +}); + document.getElementById('saveBtn').addEventListener('click', () => { if(activeDocument === null) { return; @@ -109,3 +119,7 @@ document.getElementById('importBtn').addEventListener('click', () => { document.getElementById('exportBtn').addEventListener('click', () => { modalExport.open(); }); + +document.getElementById('simulateBtn').addEventListener('click', () => { + modalSimulate.open(); +}); diff --git a/js/simulate.js b/js/simulate.js index 896a1ed..2f24d22 100644 --- a/js/simulate.js +++ b/js/simulate.js @@ -3,7 +3,7 @@ let singleCharMode = true; let simulationStepDuration = 500; function simulate(word) { - if(activeDocument !== null) { + if(activeDocument === null) { return false; } @@ -24,6 +24,8 @@ function simulate(word) { startConnections.forEach(connection => animations.push(new ConnectionAnimation(connection))); simulationStates = startConnections.map(conn => conn.state); + // TODO: Check if there are no connections and throw error message to user + setTimeout(() => { simulationStates.forEach(state => { state.isActive = true; @@ -37,6 +39,8 @@ function simulate(word) { return; } + // TODO: Check if there are any possibilities left or stop run + simulationStep(steps[stepIndex]); stepIndex++; }, simulationStepDuration * 4);