1 package erland.game.tileadventure;
2
3 import erland.util.*;
4 import erland.game.tileadventure.rect.RectBlockContainerData;
5 import erland.game.BlockContainerInterface;
6
7 import java.awt.*;
8 import java.awt.image.BufferedImage;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public class MapObjectEditorLevelManager extends LevelManager {
30 private Image paletteImage;
31 protected int getDefaultSizeX() {
32 return 1;
33 }
34
35 protected int getDefaultSizeY() {
36 return 1;
37 }
38
39 protected int getDefaultSizeZ() {
40 return 1;
41 }
42
43 protected String getGroupName() {
44 return "objects";
45 }
46
47 protected String getObjectName() {
48 return "object";
49 }
50 public Image getImage() {
51 TileGameEnvironmentInterface env = ((TileGameEnvironmentInterface)getEnvironment().getCustomEnvironment());
52 SubImageHandler subImageHandler = env.createSubImageHandler(null);
53 IrregularBlockContainerInterface cont = env.createRectBlockContainer(0,0,1,1,1);
54 boolean bEnd = false;
55 int i=0;
56 while(!bEnd) {
57 LevelInfoInterface level = getLevel(++i);
58 if(level!=null) {
59 MapObjectContainerInterface map = level.getObjects();
60 MapEditorObject o = (MapEditorObject) map.getBlock(0,0,0);
61 o.init(getEnvironment());
62 o.setContainer(cont);
63 o.setPos(0,0,0);
64 o.draw(subImageHandler.getGraphics(i-1));
65 }else {
66 bEnd = true;
67 }
68 }
69 return subImageHandler.getImage();
70 }
71
72 public LevelInfoInterface createLevel(int level) {
73 LevelInfoInterface levelInfo = getLevel(level);
74 if(levelInfo==null) {
75 MapObjectContainerInterface map = new MapBlockContainer(1,1,1);
76 MapObjectExtendedLevelInfo info = new MapObjectExtendedLevelInfo();
77 levelInfo = new LevelInfo(map,info);
78 }
79 return levelInfo;
80 }
81
82 public LevelInfoInterface getLevel(int level) {
83 StorageInterface objectStorage = LevelManagerHelper.load(getEnvironment().getStorage(),getGroupName(),getObjectName(),""+level);
84 String prefix = ((TileGameEnvironmentInterface)getEnvironment().getCustomEnvironment()).getTileType();
85 if(objectStorage!=null) {
86 MapObjectContainerInterface map = new MapBlockContainer(1,1,1);
87 MapObjectExtendedLevelInfo info = new MapObjectExtendedLevelInfo();
88 ParameterValueStorageExInterface objectParameters = new ParameterStorageStringEx(objectStorage,null,getObjectName());
89 info.read(objectParameters);
90 MapEditorObject obj = new MapEditorObject();
91 obj.init(getEnvironment());
92 obj.setContainer(getContainer());
93 obj.read(objectParameters);
94 obj.setImage(getPaletteImage(),obj.getBlockType()-1);
95 map.setBlock(obj,(int)obj.getPosX(),(int)obj.getPosY(),(int)obj.getPosZ());
96 return new LevelInfo(map,info);
97 }else {
98 return null;
99 }
100 }
101
102 public void setLevel(int level, MapObjectContainerInterface blocks, ParameterSerializable extendedInfo) {
103
104 StringStorage objectStorage = new StringStorage();
105 ParameterValueStorageExInterface objectParameters = new ParameterStorageStringEx(objectStorage,null,null);
106 MapEditorObject obj = (MapEditorObject) blocks.getBlock(0,0,0);
107 if(obj!=null) {
108 obj.write(objectParameters);
109 }
110 if(extendedInfo!=null) {
111 extendedInfo.write(objectParameters);
112 }
113
114 LevelManagerHelper.store(getEnvironment().getStorage(),getGroupName(),getObjectName(),""+level,objectStorage.load() );
115 }
116 private Image getPaletteImage() {
117 if(paletteImage==null) {
118 LevelManager levelManager = new AnimationEditorLevelManager();
119 levelManager.init(getEnvironment());
120 paletteImage = levelManager.getImage();
121 }
122 return paletteImage;
123 }
124 }