@@ -82,7 +82,7 @@ public static enum AssetState {
82
82
private boolean paused ;
83
83
private boolean cutMode ;
84
84
85
- /** keep track of the time of game in ms.*/
85
+ /** keep track of the time of game in ms. */
86
86
private long timeOfGame ;
87
87
88
88
/** for debug purposes, keep track of loading time */
@@ -114,7 +114,7 @@ public static enum AssetState {
114
114
// We not dispose the last loaded scene.
115
115
// Instead we cache it to improve performance when returning
116
116
transient private Scene cachedScene ;
117
-
117
+
118
118
private String previousScene = null ;
119
119
120
120
public static World getInstance () {
@@ -146,7 +146,7 @@ private void init() {
146
146
paused = false ;
147
147
148
148
disposed = false ;
149
-
149
+
150
150
previousScene = null ;
151
151
}
152
152
@@ -164,7 +164,7 @@ public void setCustomProperty(String name, String value) {
164
164
else
165
165
customProperties .put (name , value );
166
166
}
167
-
167
+
168
168
public String getPreviousScene () {
169
169
return previousScene ;
170
170
}
@@ -195,7 +195,7 @@ public void update(float delta) {
195
195
&& !EngineAssetManager .getInstance ().isLoading ()) {
196
196
197
197
retrieveAssets ();
198
-
198
+
199
199
paused = false ;
200
200
201
201
boolean initScene = (assetState == AssetState .LOADING_AND_INIT_SCENE );
@@ -291,7 +291,7 @@ public void setCurrentScene(Scene scene) {
291
291
ActionCallbackQueue .clear ();
292
292
293
293
if (cachedScene == scene ) {
294
- assetState = AssetState .LOADING_AND_INIT_SCENE ;
294
+ assetState = AssetState .LOADING_AND_INIT_SCENE ;
295
295
} else {
296
296
if (cachedScene != null ) {
297
297
cachedScene .dispose ();
@@ -309,11 +309,15 @@ public void setCurrentScene(Scene scene) {
309
309
currentDialog = null ;
310
310
311
311
// Stop Sounds
312
- for (BaseActor a :currentScene .getActors ().values ()) {
313
- if (a instanceof InteractiveActor )
314
- ((InteractiveActor ) a ).stopCurrentSound ();
312
+ for (BaseActor a : currentScene .getActors ().values ()) {
313
+ if (a instanceof InteractiveActor ) {
314
+ String playingSound = ((InteractiveActor ) a ).getPlayingSound ();
315
+
316
+ if (playingSound != null )
317
+ ((InteractiveActor ) a ).getSounds ().get (playingSound ).stop ();
318
+ }
315
319
}
316
-
320
+
317
321
previousScene = currentScene .getId ();
318
322
319
323
if (CACHE_ENABLED )
@@ -495,20 +499,38 @@ public boolean inCutMode() {
495
499
public void pause () {
496
500
paused = true ;
497
501
498
- if (currentScene != null )
502
+ if (currentScene != null ) {
499
503
currentScene .pauseMusic ();
500
504
501
- // TODO Pause all sounds
505
+ // Pause all sounds
506
+ for (BaseActor a : currentScene .getActors ().values ()) {
507
+ if (a instanceof InteractiveActor ) {
508
+ String playingSound = ((InteractiveActor ) a ).getPlayingSound ();
509
+
510
+ if (playingSound != null )
511
+ ((InteractiveActor ) a ).getSounds ().get (playingSound ).pause ();
512
+ }
513
+ }
514
+ }
502
515
}
503
516
504
517
public void resume () {
505
518
paused = false ;
506
519
507
520
if (assetState == AssetState .LOADED ) {
508
- if (currentScene != null )
521
+ if (currentScene != null ) {
509
522
currentScene .resumeMusic ();
510
523
511
- // TODO Resume all sounds
524
+ // Resume all sounds
525
+ for (BaseActor a : currentScene .getActors ().values ()) {
526
+ if (a instanceof InteractiveActor ) {
527
+ String playingSound = ((InteractiveActor ) a ).getPlayingSound ();
528
+
529
+ if (playingSound != null )
530
+ ((InteractiveActor ) a ).getSounds ().get (playingSound ).resume ();
531
+ }
532
+ }
533
+ }
512
534
}
513
535
}
514
536
@@ -643,9 +665,11 @@ public void loadChapter(String chapterName) throws IOException {
643
665
644
666
I18N .loadChapter (EngineAssetManager .MODEL_DIR + chapterName );
645
667
} else {
646
- EngineLogger .error ("ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager .CHAPTER_EXT + " doesn't exists." );
668
+ EngineLogger .error ("ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager .CHAPTER_EXT
669
+ + " doesn't exists." );
647
670
dispose ();
648
- throw new IOException ("ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager .CHAPTER_EXT + " doesn't exists." );
671
+ throw new IOException ("ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager .CHAPTER_EXT
672
+ + " doesn't exists." );
649
673
}
650
674
651
675
EngineLogger .debug ("MODEL LOADING TIME (ms): " + (System .currentTimeMillis () - initTime ));
@@ -667,8 +691,8 @@ public boolean savedGameExists() {
667
691
}
668
692
669
693
public boolean savedGameExists (String filename ) {
670
- return EngineAssetManager .getInstance ().getUserFile (filename ).exists () ||
671
- EngineAssetManager .getInstance ().assetExists ("tests/" + filename );
694
+ return EngineAssetManager .getInstance ().getUserFile (filename ).exists ()
695
+ || EngineAssetManager .getInstance ().assetExists ("tests/" + filename );
672
696
}
673
697
674
698
public void loadGameState () throws IOException {
@@ -679,8 +703,8 @@ public void loadGameState() throws IOException {
679
703
680
704
public void loadGameState (String filename ) throws IOException {
681
705
FileHandle savedFile = null ;
682
-
683
- if (EngineAssetManager .getInstance ().getUserFile (filename ).exists ())
706
+
707
+ if (EngineAssetManager .getInstance ().getUserFile (filename ).exists ())
684
708
savedFile = EngineAssetManager .getInstance ().getUserFile (filename );
685
709
else
686
710
savedFile = EngineAssetManager .getInstance ().getAsset ("tests/" + filename );
@@ -700,12 +724,12 @@ public void loadGameState(FileHandle savedFile) throws IOException {
700
724
SerializationHelper .getInstance ().setMode (Mode .STATE );
701
725
702
726
JsonValue root = new JsonReader ().parse (savedFile .reader ("UTF-8" ));
703
-
727
+
704
728
Json json = new Json ();
705
729
json .setIgnoreUnknownFields (true );
706
730
707
731
read (json , root );
708
-
732
+
709
733
assetState = AssetState .LOAD_ASSETS ;
710
734
711
735
} else {
@@ -716,7 +740,7 @@ public void loadGameState(FileHandle savedFile) throws IOException {
716
740
public void saveGameState () throws IOException {
717
741
saveGameState (GAMESTATE_FILENAME );
718
742
}
719
-
743
+
720
744
public void removeGameState (String filename ) throws IOException {
721
745
EngineAssetManager .getInstance ().getUserFile (filename ).delete ();
722
746
EngineAssetManager .getInstance ().getUserFile (filename + ".png" ).delete ();
@@ -887,16 +911,16 @@ public void read(Json json, JsonValue jsonData) {
887
911
SerializationHelper .getInstance ().setMode (Mode .STATE );
888
912
889
913
currentScene = scenes .get (json .readValue ("currentScene" , String .class , jsonData ));
890
-
914
+
891
915
for (Scene s : scenes .values ()) {
892
916
JsonValue jsonValue = jsonData .get ("scenes" ).get (s .getId ());
893
-
894
- if (jsonValue != null )
917
+
918
+ if (jsonValue != null )
895
919
s .read (json , jsonValue );
896
920
else
897
921
EngineLogger .debug ("LOAD WARNING: Scene not found in saved game: " + s .getId ());
898
922
}
899
-
923
+
900
924
inventory = json .readValue ("inventory" , Inventory .class , jsonData );
901
925
902
926
timeOfGame = json .readValue ("timeOfGame" , long .class , 0L , jsonData );
@@ -908,7 +932,7 @@ public void read(Json json, JsonValue jsonData) {
908
932
909
933
textManager = json .readValue ("textmanager" , TextManager .class , jsonData );
910
934
customProperties = json .readValue ("customProperties" , HashMap .class , String .class , jsonData );
911
- previousScene = json .readValue ("previousScene" , String .class , jsonData );
935
+ previousScene = json .readValue ("previousScene" , String .class , jsonData );
912
936
913
937
String actorId = json .readValue ("dialogActor" , String .class , jsonData );
914
938
String dialogId = json .readValue ("currentDialog" , String .class , jsonData );
0 commit comments