Skip to content

Commit 5bd173a

Browse files
committed
default sketch & fixed error where line was null
1 parent 9f57295 commit 5bd173a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

p5js/js/sketch.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function setup() {
2+
createCanvas(400, 400);
3+
}
4+
5+
function draw() {
6+
background(220);
7+
}

p5js/src/main/kotlin/p5js.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ class p5js(base: Base, folder: File): Mode(base, folder) {
2727
override fun getIgnorable(): Array<String> {
2828
return arrayOf("node_modules")
2929
}
30+
31+
override fun addTemplateFiles(sketchFolder: File?, sketchName: String?): File? {
32+
val sketch = super.addTemplateFiles(sketchFolder, sketchName)
33+
val defaultSketch = getContentFile("js/sketch.js")
34+
if (defaultSketch != null && sketch != null) {
35+
defaultSketch.copyTo(sketch, overwrite = true)
36+
}
37+
return sketch
38+
39+
}
3040
}

p5js/src/main/kotlin/p5jsEditor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ class p5jsEditor(base: Base, path: String?, state: EditorState?, mode: Mode?): E
303303

304304
// Handle output stream
305305
val reader = BufferedReader(InputStreamReader(process.inputStream))
306-
var line: String
306+
var line: String?
307307

308308
while (reader.readLine().also { line = it } != null) {
309309
// TODO: so much refactoring!
310310
// Only check for errors when running the sketch
311-
if (action == "pnpm sketch:start" && line.startsWith("error")) {
311+
if (action == "pnpm sketch:start" && line?.startsWith("error") == true) {
312312
// TODO: more robust data exchange, double-check with @Stef
313313
// TODO: `statusError` does not do anything with column of a SketchException
314314
val ( msgType, msgText, msgFile, msgLine, msgCol ) = line.split("|")

0 commit comments

Comments
 (0)