Add button to simulate machine

This commit is contained in:
Marcel 2019-03-05 20:31:53 +01:00
parent dc41fd7ba9
commit 6f16c5c9b7
5 changed files with 27 additions and 5 deletions

View File

@ -215,9 +215,11 @@
<button class="btn action-button" id="openBtn"><i class="fa fa-folder-open"></i> Öffnen</button> <button class="btn action-button" id="openBtn"><i class="fa fa-folder-open"></i> Öffnen</button>
<button class="btn action-button" id="importBtn"><i class="fa fa-upload"></i> Importieren</button> <button class="btn action-button" id="importBtn"><i class="fa fa-file-import"></i> Importieren</button>
<button class="btn action-button" id="exportBtn"><i class="fa fa-download"></i> Exportieren</button> <button class="btn action-button" id="exportBtn"><i class="fa fa-file-export"></i> Exportieren</button>
<button class="btn action-button" id="simulateBtn"><i class="fa fa-play"></i> Simulieren</button>
</div> </div>

View File

@ -6,7 +6,7 @@ class State {
this.y = y; this.y = y;
this.mouseOffsetX = 0; this.mouseOffsetX = 0;
this.mouseOffsetY = 0; this.mouseOffsetY = 0;
this.color = '#f0f'; this.color = '#fff';
this.isActive = false; this.isActive = false;
this.activeTime = 0; this.activeTime = 0;
this.isAcceptState = false; this.isAcceptState = false;

View File

@ -58,6 +58,7 @@ function parseFromJson(json) {
doc.states = doc.states.map(state => Object.assign(new State(0, 0), state)); doc.states = doc.states.map(state => Object.assign(new State(0, 0), state));
doc.connections = doc.connections.map(connection => { doc.connections = doc.connections.map(connection => {
console.log(connection.type);
switch(connection.type) { switch(connection.type) {
case 'Connection': case 'Connection':
connection = Object.assign(new Connection(null, null), connection); connection = Object.assign(new Connection(null, null), connection);
@ -73,9 +74,10 @@ function parseFromJson(json) {
break; break;
case 'StartConnection': 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); connection.state = doc.states.find(state => state.id === connection.state);
console.log(connection.state);
break; break;
} }

View File

@ -86,6 +86,16 @@ modalImport.addFooterBtn('Laden', 'btn', () => {
} }
}); });
const modalSimulate = new tingle.modal({
footer: true,
});
modalSimulate.setContent('<h3>Maschine simulieren</h3> <label for="simulationInput">Eingabe</label> <input type="text" id="simulationInput">');
modalSimulate.addFooterBtn('Simulation starten', 'btn', () => {
modalSimulate.close();
const input = document.getElementById('simulationInput').value;
simulate(input);
});
document.getElementById('saveBtn').addEventListener('click', () => { document.getElementById('saveBtn').addEventListener('click', () => {
if(activeDocument === null) { if(activeDocument === null) {
return; return;
@ -109,3 +119,7 @@ document.getElementById('importBtn').addEventListener('click', () => {
document.getElementById('exportBtn').addEventListener('click', () => { document.getElementById('exportBtn').addEventListener('click', () => {
modalExport.open(); modalExport.open();
}); });
document.getElementById('simulateBtn').addEventListener('click', () => {
modalSimulate.open();
});

View File

@ -3,7 +3,7 @@ let singleCharMode = true;
let simulationStepDuration = 500; let simulationStepDuration = 500;
function simulate(word) { function simulate(word) {
if(activeDocument !== null) { if(activeDocument === null) {
return false; return false;
} }
@ -24,6 +24,8 @@ function simulate(word) {
startConnections.forEach(connection => animations.push(new ConnectionAnimation(connection))); startConnections.forEach(connection => animations.push(new ConnectionAnimation(connection)));
simulationStates = startConnections.map(conn => conn.state); simulationStates = startConnections.map(conn => conn.state);
// TODO: Check if there are no connections and throw error message to user
setTimeout(() => { setTimeout(() => {
simulationStates.forEach(state => { simulationStates.forEach(state => {
state.isActive = true; state.isActive = true;
@ -37,6 +39,8 @@ function simulate(word) {
return; return;
} }
// TODO: Check if there are any possibilities left or stop run
simulationStep(steps[stepIndex]); simulationStep(steps[stepIndex]);
stepIndex++; stepIndex++;
}, simulationStepDuration * 4); }, simulationStepDuration * 4);