Skip to content

Commit e58b7bd

Browse files
committed
Little refactor in world serialization.
1 parent 3760ffd commit e58b7bd

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

blade-engine/src/com/bladecoder/engine/serialization/WorldSerialization.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,16 @@ public void saveGameState(String filename) throws IOException {
244244
@Override
245245
public void write(Json json) {
246246
BladeJson bjson = (BladeJson) json;
247+
248+
json.writeValue(Config.BLADE_ENGINE_VERSION_PROP,
249+
Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, null));
247250

248251
if (bjson.getMode() == Mode.MODEL) {
249-
json.writeValue(Config.BLADE_ENGINE_VERSION_PROP,
250-
Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, null));
251-
252252
json.writeValue("sounds", w.getSounds(), w.getSounds().getClass(), SoundDesc.class);
253253
json.writeValue("scenes", w.getScenes(), w.getScenes().getClass(), Scene.class);
254254
json.writeValue("initScene", w.getInitScene());
255255

256256
} else {
257-
json.writeValue(Config.BLADE_ENGINE_VERSION_PROP,
258-
Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, null));
259257
json.writeValue(Config.VERSION_PROP, Config.getProperty(Config.VERSION_PROP, null));
260258
json.writeValue("scenes", w.getScenes(), w.getScenes().getClass(), Scene.class);
261259
json.writeValue("currentScene", w.getCurrentScene().getId());
@@ -288,12 +286,13 @@ public void write(Json json) {
288286

289287
@Override
290288
public void read(Json json, JsonValue jsonData) {
289+
290+
String bladeVersion = json.readValue(Config.BLADE_ENGINE_VERSION_PROP, String.class, jsonData);
291291

292292
BladeJson bjson = (BladeJson) json;
293293
if (bjson.getMode() == Mode.MODEL) {
294-
String version = json.readValue(Config.BLADE_ENGINE_VERSION_PROP, String.class, jsonData);
295-
if (version != null && !version.equals(Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
296-
EngineLogger.debug("Model Engine Version v" + version + " differs from Current Engine Version v"
294+
if (bladeVersion != null && !bladeVersion.equals(Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
295+
EngineLogger.debug("Model Engine Version v" + bladeVersion + " differs from Current Engine Version v"
297296
+ Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
298297
}
299298

@@ -333,19 +332,13 @@ public void read(Json json, JsonValue jsonData) {
333332
// Add sounds to cache
334333
cacheSounds();
335334
} else {
336-
String bladeVersion = json.readValue(Config.BLADE_ENGINE_VERSION_PROP, String.class, jsonData);
337335
if (bladeVersion != null
338336
&& !bladeVersion.equals(Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
339337
EngineLogger
340338
.debug("Saved Game Engine Version v" + bladeVersion + " differs from Current Engine Version v"
341339
+ Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
342340
}
343341

344-
String version = json.readValue(Config.VERSION_PROP, String.class, jsonData);
345-
346-
if (version == null)
347-
version = "TEST";
348-
349342
String currentChapter = json.readValue("chapter", String.class, jsonData);
350343
String currentScene = json.readValue("currentScene", String.class, jsonData);
351344

@@ -402,6 +395,9 @@ public void read(Json json, JsonValue jsonData) {
402395
props.put(jsonValue.name, jsonValue.asString());
403396
}
404397

398+
String version = json.readValue(Config.VERSION_PROP, String.class, jsonData);
399+
if (version == null)
400+
version = "TEST";
405401
props.put(WorldProperties.SAVED_GAME_VERSION.toString(), version);
406402

407403
String actorId = json.readValue("dialogActor", String.class, jsonData);

0 commit comments

Comments
 (0)