View Javadoc

1   package erland.game.tileadventure;
2   
3   import erland.util.*;
4   import erland.game.GameEnvironmentInterface;
5   
6   /*
7    * Copyright (C) 2004 Erland Isaksson (erland_i@hotmail.com)
8    *
9    * This program is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU General Public License
11   * as published by the Free Software Foundation; either version 2
12   * of the License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with this program; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22   * 
23   */
24  
25  public class LevelManagerHelper {
26      public static StorageInterface load(ParameterValueStorageExInterface mainStorage, String parent, String group, String id) {
27          StorageInterface parentStorage = mainStorage.getParameterAsStorage(parent);
28          ParameterValueStorageExInterface parameters = new ParameterStorageGroupWithId(parentStorage, null, parent, group);
29          return parameters.getParameterAsStorage(group + "." + id);
30      }
31      public static void store(ParameterValueStorageExInterface storage, String parent, String group, String id, String value) {
32          StorageInterface parameterStorage = storage.getParameterAsStorage(parent);
33          ParameterStorageGroupWithId parameters = null;
34          StorageInterface updatedStorage = null;
35          if(parameterStorage==null) {
36              updatedStorage = new StringStorage();
37              parameters = new ParameterStorageGroupWithId(updatedStorage,null,null,group);
38          }else {
39              updatedStorage = parameterStorage;
40              parameters = new ParameterStorageGroupWithId(updatedStorage,null,parent,group);
41          }
42          parameters.setParameter(group+"."+id,value);
43  
44          if(parameterStorage!=null) {
45              storage.setParameterAsStorage(parent,updatedStorage);
46          }else {
47              storage.setParameter(parent,updatedStorage.load());
48          }
49      }
50  }