Skip to content

Commit 5c89923

Browse files
committed
Multi inventory support.
1 parent d7874d1 commit 5c89923

File tree

5 files changed

+53
-16
lines changed

5 files changed

+53
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [0.9.14]
6+
7+
- Multiinventory support.
8+
- EDITOR: Fix when adding custom actions.
9+
510
## [0.9.13]
611

712
- Added new buttons in the Tools menu to test the scene in Iphone/Ipad emulator and device.
8-
913
- Support for changing players in runtime: Added $PLAYER variable.
1014
- Added actor Tint attribute to allow lighting effects.
1115
- EDITOR: Disable not working HTML platform.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@
1616
package com.bladecoder.engine.actions;
1717

1818
import com.bladecoder.engine.actions.Param.Type;
19+
import com.bladecoder.engine.assets.EngineAssetManager;
1920
import com.bladecoder.engine.model.BaseActor;
2021
import com.bladecoder.engine.model.CharacterActor;
2122
import com.bladecoder.engine.model.Scene;
2223
import com.bladecoder.engine.model.VerbRunner;
24+
import com.bladecoder.engine.model.World;
2325

2426
@ActionDescription("Sets the scene player")
2527
public class SetPlayerAction implements Action {
2628

2729
@ActionProperty(type = Type.SCENE_CHARACTER_ACTOR, required = true)
2830
@ActionPropertyDescription("The scene player")
2931
private SceneActorRef actor;
32+
33+
@ActionProperty
34+
@ActionPropertyDescription("The inventory 'id' for the player. If empty, the inventory will not change.")
35+
private String inventory;
3036

3137
@Override
3238
public boolean run(VerbRunner cb) {
@@ -35,6 +41,15 @@ public boolean run(VerbRunner cb) {
3541
BaseActor a = s.getActor(actor.getActorId(), true);
3642

3743
s.setPlayer((CharacterActor)a);
44+
45+
if(inventory != null) {
46+
World w = World.getInstance();
47+
w.getInventory().dispose();
48+
w.setInventory(inventory);
49+
w.getInventory().loadAssets();
50+
EngineAssetManager.getInstance().finishLoading();
51+
w.getInventory().retrieveAssets();
52+
}
3853

3954
return false;
4055
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
@ActionDescription("Shows/Hide the inventory")
2222
public class ShowInventoryAction implements Action {
2323
@ActionProperty(required = true, defaultValue = "true")
24-
@ActionPropertyDescription("When 'true' sets the scene in 'cutmode'")
25-
24+
@ActionPropertyDescription("When 'true' shows the inventory button to show the inventory.")
2625
private boolean value = true;
2726

2827
@Override

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public class World implements Serializable, AssetConsumer {
5353

5454
public static final String GAMESTATE_EXT = ".gamestate.v11";
5555
private static final String GAMESTATE_FILENAME = "default" + GAMESTATE_EXT;
56+
57+
private static final String DEFAULT_INVENTORY="DEFAULT";
5658

5759
private static final int SCREENSHOT_DEFAULT_WIDTH = 300;
5860

@@ -79,8 +81,10 @@ public static enum WorldProperties {
7981

8082
private Scene currentScene;
8183
private Dialog currentDialog;
82-
83-
private Inventory inventory;
84+
85+
private HashMap<String, Inventory> inventories;
86+
private String currentInventory;
87+
8488
private TextManager textManager;
8589

8690
private boolean paused;
@@ -138,7 +142,9 @@ private World() {
138142
private void init() {
139143
// scenes = new HashMap<String, Scene>();
140144
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;
142148
textManager = new TextManager();
143149

144150
timers = new Timers();
@@ -272,16 +278,16 @@ else if(customProperties.get(WorldProperties.SAVED_GAME_VERSION.toString()) != n
272278
public void loadAssets() {
273279
currentScene.loadAssets();
274280

275-
if (inventory.isDisposed())
276-
inventory.loadAssets();
281+
if (getInventory().isDisposed())
282+
getInventory().loadAssets();
277283

278284
musicEngine.loadAssets();
279285
}
280286

281287
@Override
282288
public void retrieveAssets() {
283-
if (inventory.isDisposed())
284-
inventory.retrieveAssets();
289+
if (getInventory().isDisposed())
290+
getInventory().retrieveAssets();
285291

286292
getCurrentScene().retrieveAssets();
287293

@@ -386,7 +392,7 @@ private void initCurrentScene() {
386392
}
387393

388394
public Inventory getInventory() {
389-
return inventory;
395+
return inventories.get(currentInventory);
390396
}
391397

392398
public TextManager getTextManager() {
@@ -430,6 +436,17 @@ public void setCurrentDialog(Dialog dialog) {
430436
currentDialog = null;
431437
}
432438
}
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+
}
433450

434451
public void selectVisibleDialogOption(int i) {
435452
if (currentDialog == null)
@@ -455,7 +472,7 @@ public void setHeight(int height) {
455472
}
456473

457474
public void showInventory(boolean b) {
458-
inventory.setVisible(b);
475+
getInventory().setVisible(b);
459476
}
460477

461478
public boolean isDisposed() {
@@ -490,7 +507,7 @@ public void dispose() {
490507
cachedScene = null;
491508
}
492509

493-
inventory.dispose();
510+
getInventory().dispose();
494511

495512
spriteBatch.dispose();
496513

@@ -894,7 +911,8 @@ public void write(Json json) {
894911
Config.getProperty(Config.VERSION_PROP, null));
895912
json.writeValue("scenes", scenes, scenes.getClass(), Scene.class);
896913
json.writeValue("currentScene", currentScene.getId());
897-
json.writeValue("inventory", inventory);
914+
json.writeValue("inventories", inventories);
915+
json.writeValue("currentInventory", currentInventory);
898916
json.writeValue("timeOfGame", timeOfGame);
899917
json.writeValue("cutmode", cutMode);
900918
verbs.write(json);
@@ -975,7 +993,8 @@ public void read(Json json, JsonValue jsonData) {
975993
EngineLogger.debug("LOAD WARNING: Scene not found in saved game: " + s.getId());
976994
}
977995

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);
979998

980999
timeOfGame = json.readValue("timeOfGame", long.class, 0L, jsonData);
9811000
cutMode = json.readValue("cutmode", boolean.class, false, jsonData);

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=0.9.13
1+
version=0.9.14
22
libgdxVersion=1.9.3
33
roboVMVersion=2.1.0
44
roboVMGradlePluginVersion=2.1.0

0 commit comments

Comments
 (0)