@@ -53,6 +53,8 @@ public class World implements Serializable, AssetConsumer {
53
53
54
54
public static final String GAMESTATE_EXT = ".gamestate.v11" ;
55
55
private static final String GAMESTATE_FILENAME = "default" + GAMESTATE_EXT ;
56
+
57
+ private static final String DEFAULT_INVENTORY ="DEFAULT" ;
56
58
57
59
private static final int SCREENSHOT_DEFAULT_WIDTH = 300 ;
58
60
@@ -79,8 +81,10 @@ public static enum WorldProperties {
79
81
80
82
private Scene currentScene ;
81
83
private Dialog currentDialog ;
82
-
83
- private Inventory inventory ;
84
+
85
+ private HashMap <String , Inventory > inventories ;
86
+ private String currentInventory ;
87
+
84
88
private TextManager textManager ;
85
89
86
90
private boolean paused ;
@@ -138,7 +142,9 @@ private World() {
138
142
private void init () {
139
143
// scenes = new HashMap<String, Scene>();
140
144
scenes = new HashMap <String , Scene >();
141
- inventory = new Inventory ();
145
+ inventories = new HashMap <String , Inventory >();
146
+ inventories .put (DEFAULT_INVENTORY , new Inventory ());
147
+ currentInventory = DEFAULT_INVENTORY ;
142
148
textManager = new TextManager ();
143
149
144
150
timers = new Timers ();
@@ -272,16 +278,16 @@ else if(customProperties.get(WorldProperties.SAVED_GAME_VERSION.toString()) != n
272
278
public void loadAssets () {
273
279
currentScene .loadAssets ();
274
280
275
- if (inventory .isDisposed ())
276
- inventory .loadAssets ();
281
+ if (getInventory () .isDisposed ())
282
+ getInventory () .loadAssets ();
277
283
278
284
musicEngine .loadAssets ();
279
285
}
280
286
281
287
@ Override
282
288
public void retrieveAssets () {
283
- if (inventory .isDisposed ())
284
- inventory .retrieveAssets ();
289
+ if (getInventory () .isDisposed ())
290
+ getInventory () .retrieveAssets ();
285
291
286
292
getCurrentScene ().retrieveAssets ();
287
293
@@ -386,7 +392,7 @@ private void initCurrentScene() {
386
392
}
387
393
388
394
public Inventory getInventory () {
389
- return inventory ;
395
+ return inventories . get ( currentInventory ) ;
390
396
}
391
397
392
398
public TextManager getTextManager () {
@@ -430,6 +436,17 @@ public void setCurrentDialog(Dialog dialog) {
430
436
currentDialog = null ;
431
437
}
432
438
}
439
+
440
+ public void setInventory (String inventory ) {
441
+ Inventory i = inventories .get (inventory );
442
+
443
+ if (i == null ) {
444
+ i = new Inventory ();
445
+ inventories .put (inventory , i );
446
+ }
447
+
448
+ currentInventory = inventory ;
449
+ }
433
450
434
451
public void selectVisibleDialogOption (int i ) {
435
452
if (currentDialog == null )
@@ -455,7 +472,7 @@ public void setHeight(int height) {
455
472
}
456
473
457
474
public void showInventory (boolean b ) {
458
- inventory .setVisible (b );
475
+ getInventory () .setVisible (b );
459
476
}
460
477
461
478
public boolean isDisposed () {
@@ -490,7 +507,7 @@ public void dispose() {
490
507
cachedScene = null ;
491
508
}
492
509
493
- inventory .dispose ();
510
+ getInventory () .dispose ();
494
511
495
512
spriteBatch .dispose ();
496
513
@@ -894,7 +911,8 @@ public void write(Json json) {
894
911
Config .getProperty (Config .VERSION_PROP , null ));
895
912
json .writeValue ("scenes" , scenes , scenes .getClass (), Scene .class );
896
913
json .writeValue ("currentScene" , currentScene .getId ());
897
- json .writeValue ("inventory" , inventory );
914
+ json .writeValue ("inventories" , inventories );
915
+ json .writeValue ("currentInventory" , currentInventory );
898
916
json .writeValue ("timeOfGame" , timeOfGame );
899
917
json .writeValue ("cutmode" , cutMode );
900
918
verbs .write (json );
@@ -975,7 +993,8 @@ public void read(Json json, JsonValue jsonData) {
975
993
EngineLogger .debug ("LOAD WARNING: Scene not found in saved game: " + s .getId ());
976
994
}
977
995
978
- inventory = json .readValue ("inventory" , Inventory .class , jsonData );
996
+ inventories = json .readValue ("inventories" , HashMap .class , Inventory .class , jsonData );
997
+ currentInventory = json .readValue ("currentInventory" , String .class , jsonData );
979
998
980
999
timeOfGame = json .readValue ("timeOfGame" , long .class , 0L , jsonData );
981
1000
cutMode = json .readValue ("cutmode" , boolean .class , false , jsonData );
0 commit comments