21 |
21 |
22 import java.util.Collections; |
22 import java.util.Collections; |
23 import java.util.Comparator; |
23 import java.util.Comparator; |
24 import java.util.HashMap; |
24 import java.util.HashMap; |
25 import java.util.Map; |
25 import java.util.Map; |
|
26 import java.util.TreeMap; |
26 |
27 |
27 public final class Scheme { |
28 public final class Scheme { |
28 public final MetaScheme metascheme; |
|
29 public final String name; |
29 public final String name; |
30 public final Map<String, Integer> settings; |
30 public final Map<String, Integer> settings; |
31 public final Map<String, Boolean> mods; |
31 public final Map<String, Boolean> mods; |
32 |
32 |
33 public Scheme(MetaScheme metascheme, String name, Map<String, Integer> settings, Map<String, Boolean> mods) { |
33 public Scheme(String name, Map<String, Integer> settings, Map<String, Boolean> mods) { |
34 this.metascheme = metascheme; |
|
35 this.name = name; |
34 this.name = name; |
36 this.settings = Collections.unmodifiableMap(new HashMap<String, Integer>(settings)); |
35 this.settings = Collections.unmodifiableMap(new HashMap<String, Integer>(settings)); |
37 this.mods = Collections.unmodifiableMap(new HashMap<String, Boolean>(mods)); |
36 this.mods = Collections.unmodifiableMap(new HashMap<String, Boolean>(mods)); |
38 } |
37 } |
39 |
38 |
40 public int getHealth() { |
39 public int getHealth() { |
41 Integer health = settings.get("health"); |
40 Integer health = settings.get("health"); |
42 return health==null ? 100 : health.intValue(); |
41 return health==null ? 100 : health.intValue(); |
43 } |
42 } |
44 |
43 |
45 /*@Override |
44 public static Scheme createDefaultScheme(MetaScheme meta) { |
46 public String toString() { |
45 String name = GameConfig.DEFAULT_SCHEME; |
47 return "Scheme [metascheme=" + metascheme + ", name=" + name |
46 Map<String, Integer> settings = new TreeMap<String, Integer>(); |
48 + ", settings=" + settings + ", mods=" + mods + "]"; |
47 Map<String, Boolean> mods = new TreeMap<String, Boolean>(); |
49 }*/ |
48 for(MetaScheme.Setting setting : meta.settings) { |
|
49 settings.put(setting.name, setting.def); |
|
50 } |
|
51 for(MetaScheme.Mod mod : meta.mods) { |
|
52 mods.put(mod.name, Boolean.FALSE); |
|
53 } |
|
54 return new Scheme(name, settings, mods); |
|
55 } |
50 |
56 |
51 @Override |
57 @Override |
52 public String toString() { |
58 public String toString() { |
53 return name; // TODO change back once StartGameActivity does not need this anymore |
59 return "Scheme [name=" + name + ", settings=" + settings + ", mods=" |
|
60 + mods + "]"; |
54 } |
61 } |
55 |
62 |
56 public static final Comparator<Scheme> caseInsensitiveNameComparator = new Comparator<Scheme>() { |
63 @Override |
|
64 public int hashCode() { |
|
65 final int prime = 31; |
|
66 int result = 1; |
|
67 result = prime * result + ((name == null) ? 0 : name.hashCode()); |
|
68 result = prime * result + ((mods == null) ? 0 : mods.hashCode()); |
|
69 result = prime * result |
|
70 + ((settings == null) ? 0 : settings.hashCode()); |
|
71 return result; |
|
72 } |
|
73 |
|
74 @Override |
|
75 public boolean equals(Object obj) { |
|
76 if (this == obj) |
|
77 return true; |
|
78 if (obj == null) |
|
79 return false; |
|
80 if (getClass() != obj.getClass()) |
|
81 return false; |
|
82 Scheme other = (Scheme) obj; |
|
83 if (name == null) { |
|
84 if (other.name != null) |
|
85 return false; |
|
86 } else if (!name.equals(other.name)) |
|
87 return false; |
|
88 if (mods == null) { |
|
89 if (other.mods != null) |
|
90 return false; |
|
91 } else if (!mods.equals(other.mods)) |
|
92 return false; |
|
93 if (settings == null) { |
|
94 if (other.settings != null) |
|
95 return false; |
|
96 } else if (!settings.equals(other.settings)) |
|
97 return false; |
|
98 return true; |
|
99 } |
|
100 |
|
101 public static final Comparator<Scheme> NAME_ORDER = new Comparator<Scheme>() { |
57 public int compare(Scheme lhs, Scheme rhs) { |
102 public int compare(Scheme lhs, Scheme rhs) { |
58 return lhs.name.compareToIgnoreCase(rhs.name); |
103 return String.CASE_INSENSITIVE_ORDER.compare(lhs.name, rhs.name); |
59 } |
104 } |
60 }; |
105 }; |
61 } |
106 } |