Skip to content

Commit 1363522

Browse files
committed
feat: added asset loader loadCutscene shortcut
1 parent f113387 commit 1363522

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

fxgl-samples/src/main/java/sandbox/cutscene/CutsceneSample.java renamed to fxgl-samples/src/main/java/intermediate/CutsceneSample.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,34 @@
44
* See LICENSE for details.
55
*/
66

7-
package sandbox.cutscene;
7+
package intermediate;
88

99
import com.almasb.fxgl.app.GameApplication;
1010
import com.almasb.fxgl.app.GameSettings;
11-
import com.almasb.fxgl.cutscene.Cutscene;
1211
import javafx.scene.input.KeyCode;
13-
import javafx.scene.paint.Color;
1412

1513
import static com.almasb.fxgl.dsl.FXGL.*;
1614

1715
/**
16+
* Shows how to load and start cutscenes.
17+
* For cutscene format, see https://github.com/AlmasB/FXGL/wiki/Narrative-and-Dialogue-System-(FXGL-11)#cutscenes
18+
*
1819
* @author Almas Baimagambetov ([email protected])
1920
*/
2021
public class CutsceneSample extends GameApplication {
2122
@Override
22-
protected void initSettings(GameSettings settings) {
23-
settings.setWidth(1280);
24-
settings.setHeight(720);
25-
}
23+
protected void initSettings(GameSettings settings) { }
2624

2725
@Override
2826
protected void initInput() {
29-
onKeyDown(KeyCode.F, "test", () -> {
30-
// TODO: loadCutscene shortcut?
31-
var lines = getAssetLoader().loadText("example_cutscene1.txt");
32-
33-
var cutscene = new Cutscene(lines);
27+
// press F to see the cutscene
28+
onKeyDown(KeyCode.F, () -> {
29+
var cutscene = getAssetLoader().loadCutscene("example_cutscene1.txt");
3430

3531
getCutsceneService().startCutscene(cutscene);
3632
});
3733
}
3834

39-
@Override
40-
protected void initGame() {
41-
getGameScene().setBackgroundColor(Color.LIGHTGRAY);
42-
}
43-
4435
public static void main(String[] args) {
4536
launch(args);
4637
}

fxgl/src/main/kotlin/com/almasb/fxgl/app/services/FXGLAssetLoaderService.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.almasb.fxgl.core.asset.AssetLoaderService
1212
import com.almasb.fxgl.core.asset.AssetType
1313
import com.almasb.fxgl.core.asset.AssetType.*
1414
import com.almasb.fxgl.core.collection.PropertyMap
15+
import com.almasb.fxgl.cutscene.Cutscene
1516
import com.almasb.fxgl.cutscene.dialogue.DialogueGraph
1617
import com.almasb.fxgl.cutscene.dialogue.DialogueGraphSerializer
1718
import com.almasb.fxgl.cutscene.dialogue.SerializableGraph
@@ -288,6 +289,20 @@ class FXGLAssetLoaderService : AssetLoaderService() {
288289
return DialogueGraphSerializer.fromSerializable(graph)
289290
}
290291

292+
/**
293+
* @return [Cutscene] with given [name] from "/assets/text", e.g. cutscene.txt
294+
*/
295+
fun loadCutscene(name: String): Cutscene {
296+
return Cutscene(loadText(name))
297+
}
298+
299+
/**
300+
* @return [Cutscene] with given [url]
301+
*/
302+
fun loadCutscene(url: URL): Cutscene {
303+
return Cutscene(loadText(url))
304+
}
305+
291306
/**
292307
* Loads text file with given [name] from /assets/text/
293308
* into List<String> where each element represents a line in the file.

0 commit comments

Comments
 (0)