Starsector API
Loading...
Searching...
No Matches
StarGenDataSpec.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen;
2
3import java.awt.Color;
4import java.util.HashSet;
5import java.util.Set;
6
7import org.json.JSONException;
8import org.json.JSONObject;
9
10import com.fs.starfarer.api.util.Misc;
11
12public class StarGenDataSpec {
13
14
15 //id,starAge,freqYOUNG,freqAVERAGE,freqOLD,
16 //minRadius,maxRadius,coronaMin,coronaMult,coronaVar,
17 //solarWind,minFlare,maxFlare,crLossMult,lightColorMin,lightColorMax
18
19 private String id;
20 private float minRadius, maxRadius, coronaMin, coronaMult,
21 coronaVar, solarWind, minFlare, maxFlare, crLossMult,
22 freqYOUNG, freqAVERAGE, freqOLD;
23 private float probOrbits, minOrbits, maxOrbits, habZoneStart;
24 private Color lightColorMin;
25 private Color lightColorMax;
26 private StarAge age;
27
28 private Set<String> tags = new HashSet<String>();
29
30
31 public StarGenDataSpec(JSONObject row) throws JSONException {
32 id = row.getString("id");
33 minRadius = (float) row.getDouble("minRadius");
34 maxRadius = (float) row.getDouble("maxRadius");
35
36 coronaMin = (float) row.getDouble("coronaMin");
37 coronaMult = (float) row.getDouble("coronaMult");
38 coronaVar = (float) row.getDouble("coronaVar");
39
40 solarWind = (float) row.getDouble("solarWind");
41 minFlare = (float) row.getDouble("minFlare");
42 maxFlare = (float) row.getDouble("maxFlare");
43 crLossMult = (float) row.getDouble("crLossMult");
44
45 freqYOUNG = (float) row.getDouble("freqYOUNG");
46 freqAVERAGE = (float) row.getDouble("freqAVERAGE");
47 freqOLD = (float) row.getDouble("freqOLD");
48
49 probOrbits = (float) row.optDouble("probOrbits", 0);
50 minOrbits = (float) row.optDouble("minOrbits", 0);
51 maxOrbits = (float) row.optDouble("maxOrbits", 0);
52
53 habZoneStart = (float) row.optDouble("habZoneStart", 2);
54
55 age = Misc.mapToEnum(row, "age", StarAge.class, StarAge.ANY);
56
57 lightColorMin = parseColor(row.optString("lightColorMin", null) + " 255", " ");
58 lightColorMax = parseColor(row.optString("lightColorMax", null) + " 255", " ");
59
60 String tags = row.optString("tags", null);
61 if (tags != null) {
62 String [] split = tags.split(",");
63 for (String tag : split) {
64 tag = tag.trim();
65 if (tag.isEmpty()) continue;
66 addTag(tag);
67 }
68 }
69 }
70
71 public static Color parseColor(String str, String sep) {
72 if (str == null) return Color.white;
73
74 String [] parts = str.split(sep);
75 if (parts.length != 4) return Color.white;
76
77 return new Color(Integer.parseInt(parts[0].trim()),
78 Integer.parseInt(parts[1].trim()),
79 Integer.parseInt(parts[2].trim()),
80 Integer.parseInt(parts[3].trim()));
81 }
82
83 public String getId() {
84 return id;
85 }
86
87
88 public float getMinRadius() {
89 return minRadius;
90 }
91
92
93 public float getMaxRadius() {
94 return maxRadius;
95 }
96
97
98 public float getCoronaMin() {
99 return coronaMin;
100 }
101
102
103 public float getCoronaMult() {
104 return coronaMult;
105 }
106
107
108 public float getCoronaVar() {
109 return coronaVar;
110 }
111
112
113 public float getSolarWind() {
114 return solarWind;
115 }
116
117
118 public float getMinFlare() {
119 return minFlare;
120 }
121
122
123 public float getMaxFlare() {
124 return maxFlare;
125 }
126
127
128 public float getCrLossMult() {
129 return crLossMult;
130 }
131
132
133 public Color getLightColorMin() {
134 return lightColorMin;
135 }
136
137
138 public Color getLightColorMax() {
139 return lightColorMax;
140 }
141
142 public float getFreqYOUNG() {
143 return freqYOUNG;
144 }
145
146 public float getFreqAVERAGE() {
147 return freqAVERAGE;
148 }
149
150 public float getFreqOLD() {
151 return freqOLD;
152 }
153
154 public StarAge getAge() {
155 return age;
156 }
157
158 public float getProbOrbits() {
159 return probOrbits;
160 }
161
162 public float getMinOrbits() {
163 return minOrbits;
164 }
165
166 public float getMaxOrbits() {
167 return maxOrbits;
168 }
169
170 public float getHabZoneStart() {
171 return habZoneStart;
172 }
173
174 public Set<String> getTags() {
175 return tags;
176 }
177
178 public void addTag(String tag) {
179 tags.add(tag);
180 }
181
182 public boolean hasTag(String tag) {
183 return tags.contains(tag);
184 }
185}
186
187
188
189
190