Skip to content

Commit a00f16f

Browse files
authored
Merge pull request #7 from openpatch/release/alpha.11
Release Studio 0.1.0-alpha.11
2 parents d8413ce + 94136ed commit a00f16f

14 files changed

Lines changed: 62 additions & 17 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Scratch for Java Studio is a desktop IDE for students moving from Scratch to
44
Java. It builds projects with [Scratch for Java](https://github.com/openpatch/scratch-for-java)
55
and keeps them as ordinary Java source files that also work in BlueJ and VS Code.
66

7-
**Status: 0.1.0-alpha.10.** The IDE and its
7+
**Status: 0.1.0-alpha.11.** The IDE and its
88
project format may change while we test it with students and teachers.
99

1010
![Scratch for Java Studio with the code editor and the visual stage designer side by side](docs/screenshot.png)

‎app/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.10</version>
10+
<version>0.1.0-alpha.11</version>
1111
</parent>
1212

1313
<artifactId>app</artifactId>

‎core/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.10</version>
10+
<version>0.1.0-alpha.11</version>
1111
</parent>
1212

1313
<artifactId>core</artifactId>

‎export/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.10</version>
10+
<version>0.1.0-alpha.11</version>
1111
</parent>
1212

1313
<artifactId>export</artifactId>

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.openpatch.scratch4j</groupId>
88
<artifactId>scratch4j-ide</artifactId>
9-
<version>0.1.0-alpha.10</version>
9+
<version>0.1.0-alpha.11</version>
1010
<packaging>pom</packaging>
1111

1212
<name>Scratch for Java Studio</name>

‎runner/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.10</version>
10+
<version>0.1.0-alpha.11</version>
1111
</parent>
1212

1313
<artifactId>runner</artifactId>

‎runner/src/main/java/org/openpatch/scratch4j/runner/LauncherSource.java‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ static void start() {
184184
new Hook();
185185
hooked = true;
186186
}
187-
System.err.println(MARK + "frames " + frames);
187+
// "loading" while the library's loading screen shows (slow PCs stop
188+
// drawing for a while when the stage takes over)
189+
System.err.println(MARK + "frames " + frames + (loading() ? " loading" : ""));
188190
try {
189191
Thread.sleep(1000);
190192
} catch (InterruptedException e) {
@@ -358,6 +360,24 @@ static Object call(Object target, String name, Class<?>[] types, Object... args)
358360
}
359361
360362
/** The library's Processing sketch (reflective: no Processing types needed to compile). */
363+
private static java.lang.reflect.Field state;
364+
365+
/** The library still shows its loading screen (before the stage runs). */
366+
static boolean loading() {
367+
Object applet = applet();
368+
if (applet == null) return false;
369+
try {
370+
if (state == null) {
371+
java.lang.reflect.Field field = applet.getClass().getDeclaredField("state");
372+
field.setAccessible(true);
373+
state = field;
374+
}
375+
return String.valueOf(state.get(applet)).equals("LOADING");
376+
} catch (ReflectiveOperationException | RuntimeException e) {
377+
return false; // an older library: no loading screen to wait for
378+
}
379+
}
380+
361381
static Object applet() {
362382
try {
363383
return Class.forName("org.openpatch.scratch.internal.Applet")

‎runner/src/main/java/org/openpatch/scratch4j/runner/RunHandle.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ public void stop() {
8888
private static void control(String message, RunListener listener) {
8989
if (message.startsWith("frames ")) {
9090
try {
91-
listener.onFrames(Long.parseLong(message.substring("frames ".length()).trim()));
91+
String[] beat = message.substring("frames ".length()).trim().split(" ");
92+
listener.onFrames(Long.parseLong(beat[0]),
93+
beat.length > 1 && beat[1].equals("loading"));
9294
} catch (NumberFormatException ignored) {
9395
// a garbled heartbeat is skipped
9496
}

‎runner/src/main/java/org/openpatch/scratch4j/runner/RunListener.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ default void onCompileFailed(org.openpatch.scratch4j.core.compile.CompileResult
1818
*/
1919
default void onFrames(long frames) {}
2020

21+
/**
22+
* The heartbeat with whether the library still shows its loading screen
23+
* (where a slow PC may draw nothing for a while). Defaults to {@link #onFrames(long)}.
24+
*/
25+
default void onFrames(long frames, boolean loading) {
26+
onFrames(frames);
27+
}
28+
2129
/** The game loop stopped ({@code pause}, or after a {@code step}) at this frame. */
2230
default void onPaused(long frame) {}
2331

‎runner/src/test/java/org/openpatch/scratch4j/runner/IdeControlIT.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,14 @@ void aForeverLoopInRunStopsTheFrameCount() throws Exception {
231231
+ " while (true) { }\n }\n }"));
232232
ScratchProject project = ScratchProject.open(tmp.resolve("frozen"));
233233
List<Long> beats = new CopyOnWriteArrayList<>();
234+
List<Boolean> loading = new CopyOnWriteArrayList<>();
234235
RunHandle handle = new ProjectRunner().run(project,
235236
RunConfig.of(project.startStage()).withControl(),
236237
new RunListener() {
237-
@Override public void onFrames(long f) { beats.add(f); }
238+
@Override public void onFrames(long f, boolean l) {
239+
beats.add(f);
240+
loading.add(l);
241+
}
238242
});
239243
try {
240244
waitFor(() -> beats.size() >= 8 && beats.get(beats.size() - 1) > 0, 20000);
@@ -243,6 +247,8 @@ void aForeverLoopInRunStopsTheFrameCount() throws Exception {
243247
assertThat(beats.get(beats.size() - 1)).as("frozen: no new frames").isEqualTo(last);
244248
// run() starts a few frames after the first drawn frame
245249
assertThat(last).isBetween(55L, 200L);
250+
// past the loading screen: the IDE's short freeze limit applies
251+
assertThat(loading.get(loading.size() - 1)).as("loading flags %s", loading).isFalse();
246252
} finally {
247253
handle.stop();
248254
}

0 commit comments

Comments
 (0)