View Javadoc

1   package erland.game.tileadventure;
2   
3   import erland.util.ParameterSerializable;
4   import erland.util.ParameterValueStorageExInterface;
5   import erland.util.StringUtil;
6   
7   import java.util.StringTokenizer;
8   
9   /*
10   * Copyright (C) 2004 Erland Isaksson (erland_i@hotmail.com)
11   *
12   * This program is free software; you can redistribute it and/or
13   * modify it under the terms of the GNU General Public License
14   * as published by the Free Software Foundation; either version 2
15   * of the License, or (at your option) any later version.
16   *
17   * This program is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   * GNU General Public License for more details.
21   *
22   * You should have received a copy of the GNU General Public License
23   * along with this program; if not, write to the Free Software
24   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25   * 
26   */
27  
28  public class AnimationExtendedLevelInfo implements ParameterSerializable {
29      private int speed = 1;
30      private int[] images;
31  
32      public void write(ParameterValueStorageExInterface out) {
33          out.setParameter("speed",""+speed);
34          StringBuffer sb = new StringBuffer();
35          for (int i = 0; i < images.length; i++) {
36              sb.append(images[i]);
37              if(i<images.length-1) {
38                  sb.append(' ');
39              }
40          }
41          out.setParameter("images",sb.toString());
42      }
43  
44      public void read(ParameterValueStorageExInterface in) {
45          speed = StringUtil.asInteger(in.getParameter("speed"),new Integer(1)).intValue();
46          StringTokenizer tokens = new StringTokenizer(StringUtil.asEmpty(in.getParameter("images")));
47          images = new int[tokens.countTokens()];
48          int i=0;
49          while (tokens.hasMoreTokens()) {
50              String s = (String) tokens.nextToken();
51              images[i++] = StringUtil.asInteger(s,new Integer(0)).intValue();
52          }
53      }
54  
55      public int getSpeed() {
56          return speed;
57      }
58  
59      public void setSpeed(int speed) {
60          this.speed = speed;
61      }
62  
63      public int[] getImages() {
64          return images;
65      }
66  
67      public void setImages(int[] images) {
68          this.images = images;
69      }
70  }