Skip to content

Commit 12e0033

Browse files
committed
VoiceManager show log and continues when the voice file is not found instead of crash.
1 parent 5982f5a commit 12e0033

File tree

5 files changed

+86
-82
lines changed

5 files changed

+86
-82
lines changed

blade-engine/src/com/bladecoder/engine/BladeEngine.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,9 @@ public void dispose() {
196196
public void render() {
197197
ui.render();
198198

199-
// Pause the game and save state when an error is found
199+
// Pause the game when an error is found in debug mode
200200
if (EngineLogger.lastError != null && EngineLogger.debugMode() && !World.getInstance().isPaused()) {
201-
ui.pause();
202-
try {
203-
World.getInstance().saveGameState();
204-
} catch (IOException e) {
205-
EngineLogger.error(e.getMessage());
206-
}
201+
pause();
207202
}
208203
}
209204

@@ -220,7 +215,8 @@ public void pause() {
220215
boolean bot = ui.getTesterBot().isEnabled();
221216
boolean r = ui.getRecorder().isPlaying();
222217

223-
if (!bot && !r && !World.getInstance().isDisposed()) {
218+
if (!World.getInstance().isDisposed() &&
219+
((!bot && !r) || EngineLogger.lastError != null)) {
224220
EngineLogger.debug("GAME PAUSE");
225221
ui.pause();
226222
try {
@@ -237,12 +233,6 @@ public void pause() {
237233
public void resume() {
238234
EngineLogger.debug("GAME RESUME");
239235
ui.resume();
240-
241-
// resets the error when continue
242-
if (EngineLogger.lastError != null && EngineLogger.debugMode()) {
243-
EngineLogger.lastError = null;
244-
EngineLogger.lastException = null;
245-
}
246236
}
247237

248238
}

blade-engine/src/com/bladecoder/engine/actions/SayAction.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,29 @@ public boolean run(VerbRunner cb) {
6262
float x = TextManager.POS_SUBTITLE, y = TextManager.POS_SUBTITLE;
6363
Color color = null;
6464

65+
if (text == null)
66+
return false;
67+
6568
setVerbCb(cb);
6669
InteractiveActor a = (InteractiveActor) World.getInstance().getCurrentScene().getActor(actor, false);
6770

68-
if (voiceId != null)
69-
a.playSound(voiceId);
70-
71-
if (text != null) {
72-
if (type == Text.Type.TALK && a != null) {
73-
Rectangle boundingRectangle = a.getBBox().getBoundingRectangle();
74-
75-
x = boundingRectangle.getX() + boundingRectangle.getWidth() / 2;
76-
y = boundingRectangle.getY() + boundingRectangle.getHeight();
71+
if (type == Text.Type.TALK && a != null) {
72+
Rectangle boundingRectangle = a.getBBox().getBoundingRectangle();
7773

78-
color = ((CharacterActor) a).getTextColor();
74+
x = boundingRectangle.getX() + boundingRectangle.getWidth() / 2;
75+
y = boundingRectangle.getY() + boundingRectangle.getHeight();
7976

80-
restoreStandPose((CharacterActor) a);
81-
startTalkAnim((CharacterActor) a);
82-
}
77+
color = ((CharacterActor) a).getTextColor();
8378

84-
World.getInstance().getTextManager().addText(text, x, y, queue, type, color, null,
85-
a != null? a.getId(): actor, voiceId, this);
79+
restoreStandPose((CharacterActor) a);
80+
startTalkAnim((CharacterActor) a);
8681
}
8782

83+
World.getInstance().getTextManager().addText(text, x, y, queue, type, color, null,
84+
a != null ? a.getId() : actor, voiceId, this);
85+
8886
return getWait();
87+
8988
}
9089

9190
@Override
@@ -103,7 +102,7 @@ private void restoreStandPose(CharacterActor a) {
103102
if (a == null)
104103
return;
105104

106-
String fa = ((AnimationRenderer)a.getRenderer()).getCurrentAnimationId();
105+
String fa = ((AnimationRenderer) a.getRenderer()).getCurrentAnimationId();
107106

108107
// If the actor was already talking we restore the actor to the 'stand'
109108
// pose
@@ -115,7 +114,7 @@ private void restoreStandPose(CharacterActor a) {
115114
}
116115

117116
private void startTalkAnim(CharacterActor a) {
118-
previousAnim = ((AnimationRenderer)a.getRenderer()).getCurrentAnimationId();
117+
previousAnim = ((AnimationRenderer) a.getRenderer()).getCurrentAnimationId();
119118

120119
if (animation != null)
121120
a.startAnimation(animation, null);

blade-engine/src/com/bladecoder/engine/actions/TextAction.java

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class TextAction implements Action {
3232
@ActionPropertyDescription("The 'text' to show")
3333
@ActionProperty(type = Type.SMALL_TEXT)
3434
private String text;
35-
35+
3636
@ActionPropertyDescription("The 'voice' file to play if selected.")
3737
@ActionProperty(type = Type.VOICE)
3838
private String voiceId;
@@ -44,7 +44,6 @@ public class TextAction implements Action {
4444
@ActionPropertyDescription("The color to use for the font (RRGGBBAA). If not set, the default color defined in the style is used.")
4545
@ActionProperty(type = Type.COLOR)
4646
private Color color;
47-
4847

4948
@ActionProperty
5049
@ActionPropertyDescription("Obtain the text position from this actor.")
@@ -61,56 +60,58 @@ public class TextAction implements Action {
6160
@ActionProperty(defaultValue = "false")
6261
@ActionPropertyDescription("Queue the text if other text is showing, or show it immediately.")
6362
private boolean queue = false;
64-
63+
6564
@ActionProperty(required = true)
6665
@ActionPropertyDescription("If this param is 'false' the text is showed and the action continues inmediatly")
6766
private boolean wait = true;
6867

6968
@Override
7069
public boolean run(VerbRunner cb) {
7170

72-
if (text != null) {
73-
float x = TextManager.POS_CENTER, y = TextManager.POS_CENTER;
74-
75-
if (target != null) {
76-
Scene ts = target.getScene();
77-
BaseActor anchorActor = ts.getActor(target.getActorId(), true);
78-
79-
x = anchorActor.getX();
80-
y = anchorActor.getY();
81-
82-
if (anchorActor instanceof InteractiveActor) {
83-
Vector2 refPoint = ((InteractiveActor) anchorActor).getRefPoint();
84-
x += refPoint.x;
85-
y += refPoint.y;
86-
}
87-
88-
if(pos != null){
89-
float scale = EngineAssetManager.getInstance().getScale();
90-
91-
x += pos.x * scale;
92-
y += pos.y * scale;
93-
}
94-
} else if (pos != null) {
71+
if (text == null)
72+
return false;
73+
74+
float x = TextManager.POS_CENTER, y = TextManager.POS_CENTER;
75+
76+
if (target != null) {
77+
Scene ts = target.getScene();
78+
BaseActor anchorActor = ts.getActor(target.getActorId(), true);
79+
80+
x = anchorActor.getX();
81+
y = anchorActor.getY();
82+
83+
if (anchorActor instanceof InteractiveActor) {
84+
Vector2 refPoint = ((InteractiveActor) anchorActor).getRefPoint();
85+
x += refPoint.x;
86+
y += refPoint.y;
87+
}
88+
89+
if (pos != null) {
9590
float scale = EngineAssetManager.getInstance().getScale();
96-
97-
if(pos.x != TextManager.POS_CENTER)
98-
x = pos.x * scale;
99-
100-
if(pos.y != TextManager.POS_CENTER)
101-
y = pos.y * scale;
102-
103-
} else {
104-
105-
if (type == Text.Type.SUBTITLE) {
106-
x = y = TextManager.POS_SUBTITLE;
107-
}
91+
92+
x += pos.x * scale;
93+
y += pos.y * scale;
10894
}
95+
} else if (pos != null) {
96+
float scale = EngineAssetManager.getInstance().getScale();
97+
98+
if (pos.x != TextManager.POS_CENTER)
99+
x = pos.x * scale;
100+
101+
if (pos.y != TextManager.POS_CENTER)
102+
y = pos.y * scale;
103+
104+
} else {
109105

110-
World.getInstance().getTextManager()
111-
.addText(text, x, y, queue, type, color, style, null, voiceId, wait?cb:null);
106+
if (type == Text.Type.SUBTITLE) {
107+
x = y = TextManager.POS_SUBTITLE;
108+
}
112109
}
113-
110+
111+
World.getInstance().getTextManager().addText(text, x, y, queue, type, color, style, null, voiceId,
112+
wait ? cb : null);
113+
114114
return wait;
115+
115116
}
116117
}

blade-engine/src/com/bladecoder/engine/model/VoiceManager.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.badlogic.gdx.audio.Music;
44
import com.badlogic.gdx.audio.Music.OnCompletionListener;
5+
import com.badlogic.gdx.utils.GdxRuntimeException;
56
import com.badlogic.gdx.utils.Json;
67
import com.badlogic.gdx.utils.Json.Serializable;
78
import com.badlogic.gdx.utils.JsonValue;
@@ -64,7 +65,9 @@ public void play(String fileName) {
6465

6566
if (fileName != null) {
6667
retrieveAssets();
67-
voice.play();
68+
69+
if(voice != null)
70+
voice.play();
6871
}
6972
}
7073

@@ -109,7 +112,16 @@ public void retrieveAssets() {
109112

110113
if(!EngineAssetManager.getInstance().isLoaded(EngineAssetManager.VOICE_DIR + fileName)) {
111114
loadAssets();
112-
EngineAssetManager.getInstance().finishLoading();
115+
116+
try {
117+
EngineAssetManager.getInstance().finishLoading();
118+
} catch (GdxRuntimeException e) {
119+
EngineLogger.error(e.getMessage());
120+
voice = null;
121+
fileName = null;
122+
textManager.next();
123+
return;
124+
}
113125
}
114126

115127
EngineLogger.debug("RETRIEVING VOICE: " + fileName);

blade-engine/src/com/bladecoder/engine/ui/defaults/DefaultSceneScreen.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,8 @@ public boolean tap(float x, float y, int count, int button) {
155155
} else if (state == UIStates.INVENTORY_MODE) {
156156
inventoryUI.hide();
157157
} else if (state == UIStates.SCENE_MODE) {
158-
if (button == 2) { // Show
159-
// inventory
160-
// with
161-
// the
162-
// middle
163-
// button
158+
if (button == 2) {
159+
// Show inventory with the middle button
164160
if (!inventoryUI.isVisible())
165161
inventoryUI.show();
166162
} else {
@@ -265,9 +261,9 @@ public boolean keyTyped(char character) {
265261
break;
266262
case 'p':
267263
if (World.getInstance().isPaused()) {
268-
World.getInstance().resume();
264+
resume();
269265
} else {
270-
World.getInstance().pause();
266+
pause();
271267
}
272268
break;
273269
case ' ':
@@ -965,6 +961,12 @@ public void pause() {
965961
@Override
966962
public void resume() {
967963
World.getInstance().resume();
964+
965+
// resets the error when continue
966+
if (EngineLogger.lastError != null && EngineLogger.debugMode()) {
967+
EngineLogger.lastError = null;
968+
EngineLogger.lastException = null;
969+
}
968970
}
969971

970972
public Viewport getViewport() {

0 commit comments

Comments
 (0)