Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 835 | chris | 1 | package com.gebauz.bauzoid.app; |
| 2 | |||
| 3 | import java.util.HashMap; |
||
| 4 | |||
| 5 | import com.badlogic.gdx.files.FileHandle; |
||
| 6 | import com.gebauz.bauzoid.parser.Preprocessor; |
||
| 7 | import com.gebauz.bauzoid.parser.ScanException; |
||
| 8 | import com.gebauz.bauzoid.parser.Tokenizer; |
||
| 9 | |||
| 10 | public class Settings |
||
| 11 | { |
||
| 12 | // Constants======================================================================================== |
||
| 13 | |||
| 14 | public static final String LOG_TAG = "Settings"; |
||
| 15 | |||
| 16 | // Embedded Types=================================================================================== |
||
| 17 | |||
| 18 | // Members========================================================================================== |
||
| 19 | |||
| 20 | protected HashMap<String, String> mSettingsMap = new HashMap<String, String>(); |
||
| 21 | |||
| 22 | // Methods========================================================================================== |
||
| 23 | |||
| 24 | public void loadSettings(FileHandle file) |
||
| 25 | { |
||
| 26 | String fileContents = file.readString(); |
||
| 27 | |||
| 28 | Tokenizer t = new Tokenizer(Preprocessor.stripComments(fileContents, "#", "", "")); |
||
| 29 | |||
| 30 | try |
||
| 31 | { |
||
| 32 | while (!t.checkNoMoreTokens()) |
||
| 33 | { |
||
| 34 | String key = t.readIdentifier(); |
||
| 35 | t.readToken("="); |
||
| 36 | String value = t.readUntilNewLine(); |
||
| 37 | |||
| 38 | setSetting(key, value); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | catch (ScanException e) |
||
| 42 | { |
||
| 43 | e.log(LOG_TAG); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | /** Can be Overridden by derived classes in order to store values in variables to minimize HashMap access. */ |
||
| 48 | public void handleSetting(String key, String value) |
||
| 49 | { |
||
| 50 | } |
||
| 51 | |||
| 52 | // Getters/Setters================================================================================== |
||
| 53 | |||
| 54 | /** Get Settings value. */ |
||
| 55 | public final String getSetting(String key) |
||
| 56 | { |
||
| 57 | if (!mSettingsMap.containsKey(key)) |
||
| 58 | return ""; |
||
| 59 | |||
| 60 | return mSettingsMap.get(key); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** Set Settings value. */ |
||
| 64 | public final void setSetting(String key, String value) |
||
| 65 | { |
||
| 66 | mSettingsMap.put(key, value); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | |||
| 71 |