|
1 |
| -/******************************************************************************* |
2 |
| - * Copyright 2014 Rafael Garcia Moreno. |
3 |
| - * |
4 |
| - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| - * you may not use this file except in compliance with the License. |
6 |
| - * You may obtain a copy of the License at |
7 |
| - * |
8 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
9 |
| - * |
10 |
| - * Unless required by applicable law or agreed to in writing, software |
11 |
| - * distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| - * See the License for the specific language governing permissions and |
14 |
| - * limitations under the License. |
15 |
| - ******************************************************************************/ |
16 |
| -package com.bladecoder.engine.actions; |
17 |
| - |
18 |
| -import com.bladecoder.engine.actions.Param.Type; |
19 |
| -import com.bladecoder.engine.assets.EngineAssetManager; |
20 |
| -import com.bladecoder.engine.model.AnimationRenderer; |
21 |
| -import com.bladecoder.engine.model.InteractiveActor; |
22 |
| -import com.bladecoder.engine.model.Scene; |
23 |
| -import com.bladecoder.engine.model.SpriteActor; |
24 |
| -import com.bladecoder.engine.model.VerbRunner; |
25 |
| -import com.bladecoder.engine.model.World; |
26 |
| -import com.bladecoder.engine.util.EngineLogger; |
27 |
| - |
28 |
| -@ActionDescription("Puts the selected actor in the inventory.") |
29 |
| -public class PickUpAction implements Action { |
30 |
| - @ActionProperty(type = Type.SCENE_SPRITE_ACTOR, required = true) |
31 |
| - @ActionPropertyDescription("The target actor") |
32 |
| - private SceneActorRef actor; |
33 |
| - |
34 |
| - @ActionProperty |
35 |
| - @ActionPropertyDescription("The animation/sprite to show while in inventory. If empty, the animation will be 'actorid.inventory'") |
36 |
| - private String animation; |
37 |
| - |
38 |
| - @Override |
39 |
| - public boolean run(VerbRunner cb) { |
40 |
| - Scene scn = this.actor.getScene(); |
41 |
| - InteractiveActor actor = (InteractiveActor)scn.getActor(this.actor.getActorId(), false); |
42 |
| - |
43 |
| - if(actor == null) { |
44 |
| - EngineLogger.error("PickUpAction - Actor not found:" + this.actor.getActorId()); |
45 |
| - |
46 |
| - return false; |
47 |
| - } |
48 |
| - |
49 |
| - scn.removeActor(actor); |
50 |
| - |
51 |
| - if (scn != World.getInstance().getCurrentScene()) { |
52 |
| - actor.loadAssets(); |
53 |
| - EngineAssetManager.getInstance().finishLoading(); |
54 |
| - actor.retrieveAssets(); |
55 |
| - } |
56 |
| - |
57 |
| - if (actor instanceof SpriteActor) { |
58 |
| - SpriteActor a = (SpriteActor) actor; |
59 |
| - |
60 |
| - if(animation != null) |
61 |
| - a.startAnimation(animation, null); |
62 |
| - else if(((AnimationRenderer)a.getRenderer()).getAnimations().get(a.getId() + ".inventory") != null) |
63 |
| - a.startAnimation(a.getId() + ".inventory", null); |
64 |
| - |
65 |
| - World.getInstance().getInventory().addItem(a); |
66 |
| - } |
67 |
| - |
68 |
| - return false; |
69 |
| - } |
70 |
| - |
71 |
| - |
72 |
| -} |
| 1 | +/******************************************************************************* |
| 2 | + * Copyright 2014 Rafael Garcia Moreno. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + ******************************************************************************/ |
| 16 | +package com.bladecoder.engine.actions; |
| 17 | + |
| 18 | +import com.bladecoder.engine.actions.Param.Type; |
| 19 | +import com.bladecoder.engine.assets.EngineAssetManager; |
| 20 | +import com.bladecoder.engine.model.AnimationRenderer; |
| 21 | +import com.bladecoder.engine.model.InteractiveActor; |
| 22 | +import com.bladecoder.engine.model.Scene; |
| 23 | +import com.bladecoder.engine.model.SpriteActor; |
| 24 | +import com.bladecoder.engine.model.VerbRunner; |
| 25 | +import com.bladecoder.engine.model.World; |
| 26 | +import com.bladecoder.engine.util.EngineLogger; |
| 27 | + |
| 28 | +@ActionDescription("Puts the selected actor in the inventory.") |
| 29 | +public class PickUpAction implements Action { |
| 30 | + @ActionProperty(type = Type.SCENE_SPRITE_ACTOR, required = true) |
| 31 | + @ActionPropertyDescription("The target actor") |
| 32 | + private SceneActorRef actor; |
| 33 | + |
| 34 | + @ActionProperty |
| 35 | + @ActionPropertyDescription("The animation/sprite to show while in inventory. If empty, the animation will be 'actorid.inventory'") |
| 36 | + private String animation; |
| 37 | + |
| 38 | + @Override |
| 39 | + public boolean run(VerbRunner cb) { |
| 40 | + Scene scn = this.actor.getScene(); |
| 41 | + InteractiveActor actor = (InteractiveActor) scn.getActor(this.actor.getActorId(), false); |
| 42 | + |
| 43 | + if (actor == null) { |
| 44 | + EngineLogger.error("PickUpAction - Actor not found:" + this.actor.getActorId()); |
| 45 | + |
| 46 | + return false; |
| 47 | + } |
| 48 | + |
| 49 | + scn.removeActor(actor); |
| 50 | + |
| 51 | + if (scn != World.getInstance().getCurrentScene()) { |
| 52 | + actor.loadAssets(); |
| 53 | + EngineAssetManager.getInstance().finishLoading(); |
| 54 | + actor.retrieveAssets(); |
| 55 | + } |
| 56 | + |
| 57 | + if (actor instanceof SpriteActor) { |
| 58 | + SpriteActor a = (SpriteActor) actor; |
| 59 | + |
| 60 | + if (a.getRenderer() instanceof AnimationRenderer) { |
| 61 | + if (animation != null) |
| 62 | + a.startAnimation(animation, null); |
| 63 | + else if (((AnimationRenderer) a.getRenderer()).getAnimations().get(a.getId() + ".inventory") != null) |
| 64 | + a.startAnimation(a.getId() + ".inventory", null); |
| 65 | + } |
| 66 | + |
| 67 | + World.getInstance().getInventory().addItem(a); |
| 68 | + } |
| 69 | + |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments