1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
<script>
import { onMount, onDestroy } from "svelte";
import { pop } from "svelte-spa-router";
import EditorActionButton from "../../ComponentLib/Button/EditorActionButton.svelte";
import TopBar from "./TopBar.svelte";
import Pane from "./Pane.svelte";
import Controls from "./Controls.svelte";
import Output from "./Output.svelte";
import Simulation from "./Simulation.svelte";
import { authorizedSocket, authorizedSocketNeeded, openSocketConnected } from "../../stores/socketStore";
authorizedSocketNeeded.set(true);
import { attachCodeEditorView, initDebugger, closeDebugger, procIsRunning, codeEditorHasChanges, saveCode, notifErr } from "../../stores/IDEStore";
export let modeId;
let codeEditorEl;
//let failCount = 0;
//function handleError(err) {
// if (err.success) { return; }
// failCount++;
// if (failCount < 10) {
// if (err.reason == "debugger not open") {
// if (!reconnecting) {
// reconnecting = true;
// console.log("emitting editor:open");
// authorizedSocket.emit("editor:open", `user/${modeId}`, (res) => {
// reconnecting = false;
// handleError(res);
// });
// }
// } else {
// notifErr(err);
// }
// } else {
// notifErr(err);
// }
//}
function startProc() {
saveCode((res) => {
if (!res.success) { notifErr(res); };
console.debug("emitting editor:startmode");
authorizedSocket.emit("editor:startmode", (res) => {
if (!res.success) { notifErr(res); };
});
});
}
function stopProc() {
console.debug("emitting editor:stopmode");
authorizedSocket.emit("editor:stopmode", (res) => {
if (!res.success) { notifErr(res); };
});
}
function restartProc () {
saveCode((res) => {
if (!res.success) { notifErr(res); };
console.debug("emitting editor:restartmode");
authorizedSocket.emit("editor:restartmode", (res) => {
if (!res.success) { notifErr(res); };
});
});
}
let simulationEnabled;
let simulationToggleFn;
let simulationBackgrounds = ["--default-bg", "black", "white"];
let simlulationBackgroundI = 0;
function toggleSimulationPower() { simulationToggleFn(); }
function nextSimulationBackground() {
simlulationBackgroundI++;
if (simlulationBackgroundI >= simulationBackgrounds.length) {
simlulationBackgroundI = 0;
}
}
onMount(() => {
initDebugger(modeId);
attachCodeEditorView(codeEditorEl);
});
onDestroy(() => {
closeDebugger();
})
document.addEventListener("keydown", function(e) {
if ((window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && e.keyCode == 83) {
e.preventDefault();
saveCode();
}
}, false);
setInterval(() => {
if ($codeEditorHasChanges) {
saveCode();
}
}, 5000);
</script>
<style>
main {
display: grid;
box-sizing: border-box;
padding: 15px;
column-gap: 15px;
row-gap: 15px;
grid-template-columns: 300px 1fr;
grid-template-rows: 50% 1fr 33%;
grid-template-areas:
"simulation editor"
"controls editor"
"controls output";
width: 100%;
height: calc(100% - 35px);
background-color: #333333;
color: white;
}
.simulation { grid-area: simulation; }
.controls { grid-area: controls; }
.editor { grid-area: editor; }
.output { grid-area: output; }
.editor {
overflow: auto;
}
@media (max-width: 800px) {
main {
grid-template-columns: auto;
grid-template-areas:
"editor"
"editor"
"output";
}
.controls, .simulation {
display: none;
}
}
</style>
<TopBar modeId={modeId}
hasChange={$codeEditorHasChanges}
on:closedebugger={pop}
on:start={startProc}
on:stop={stopProc}
on:restart={restartProc}
bind:procIsRunning={$procIsRunning} />
<main>
<div class="simulation">
<Pane header="simulation" contentBackground={simulationBackgrounds[simlulationBackgroundI]}>
<svelte:fragment slot="actions">
<EditorActionButton faIcon="fas fa-tint"
on:click={nextSimulationBackground}
alt="Toggle simulation"></EditorActionButton>
<EditorActionButton faIcon="fas fa-power-off"
on:click={toggleSimulationPower}
color={simulationEnabled ? "green" : "red"}
alt="Toggle simulation"></EditorActionButton>
</svelte:fragment>
<Simulation bind:toggleEnable={simulationToggleFn} bind:enabled={simulationEnabled} />
</Pane>
</div>
<div class="controls">
<Pane header="Controls">
<Controls />
</Pane>
</div>
<div class="editor" bind:this={codeEditorEl}></div>
<div class="output">
<Pane header="output" padding={false} scrollable={false}>
<Output />
</Pane>
</div>
</main>
|