Skip to content

Commit 48bd749

Browse files
committed
Improve inventory loading when changing players.
1 parent 3ef5cfe commit 48bd749

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.bladecoder.engine.assets.EngineAssetManager;
2020
import com.bladecoder.engine.model.BaseActor;
2121
import com.bladecoder.engine.model.CharacterActor;
22+
import com.bladecoder.engine.model.Inventory;
2223
import com.bladecoder.engine.model.Scene;
2324
import com.bladecoder.engine.model.VerbRunner;
2425
import com.bladecoder.engine.model.World;
@@ -27,34 +28,38 @@
2728
public class SetPlayerAction implements Action {
2829

2930
@ActionProperty(type = Type.SCENE_CHARACTER_ACTOR, required = true)
30-
@ActionPropertyDescription("The scene player")
31+
@ActionPropertyDescription("The scene player")
3132
private SceneActorRef actor;
32-
33+
3334
@ActionProperty
34-
@ActionPropertyDescription("The inventory 'id' for the player. If empty, the inventory will not change.")
35+
@ActionPropertyDescription("The inventory 'id' for the player. If empty, the inventory will not change.")
3536
private String inventory;
36-
37+
3738
private World w;
38-
39+
3940
@Override
4041
public void init(World w) {
4142
this.w = w;
4243
}
4344

4445
@Override
45-
public boolean run(VerbRunner cb) {
46+
public boolean run(VerbRunner cb) {
4647
Scene s = actor.getScene(w);
4748

4849
BaseActor a = s.getActor(actor.getActorId(), true);
49-
50-
s.setPlayer((CharacterActor)a);
51-
52-
if(inventory != null) {
53-
w.getInventory().dispose();
50+
51+
s.setPlayer((CharacterActor) a);
52+
53+
if (inventory != null && !inventory.equals(w.getCurrentInventory())) {
54+
Inventory old = w.getInventory();
55+
5456
w.setInventory(inventory);
5557
w.getInventory().loadAssets();
5658
EngineAssetManager.getInstance().finishLoading();
5759
w.getInventory().retrieveAssets();
60+
61+
old.dispose();
62+
5863
}
5964

6065
return false;

0 commit comments

Comments
 (0)