Starsector API
Loading...
Searching...
No Matches
PlanetGenDataSpec.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen;
2
3import java.awt.Color;
4import java.util.HashMap;
5import java.util.HashSet;
6import java.util.Map;
7import java.util.Set;
8
9import org.json.JSONException;
10import org.json.JSONObject;
11
12public class PlanetGenDataSpec implements EntityGenDataSpec {
13
14
15 //id category frequency habOffsetMin habOffsetMax minRadius maxRadius minColor maxColor
16 private String id, category;
17 private float frequency, habOffsetMin, habOffsetMax, minRadius, maxRadius;
18 private float probOrbits, minOrbits, maxOrbits;
19 private float habOffsetYOUNG, habOffsetAVERAGE, habOffsetOLD;
20 private Color minColor, maxColor;
21
22 private Map<String, Float> multipliers = new HashMap<String, Float>();
23 private Set<String> tags = new HashSet<String>();
24
25 public PlanetGenDataSpec(JSONObject row) throws JSONException {
26 id = row.getString("id");
27 category = row.getString("category");
28 frequency = (float) row.getDouble("frequency");
29 habOffsetMin = (float) row.optDouble("habOffsetMin", -1000);
30 habOffsetMax = (float) row.optDouble("habOffsetMax", 1000);
31 minRadius = (float) row.optDouble("minRadius", 0);
32 maxRadius = (float) row.optDouble("maxRadius", 0);
33
34 habOffsetYOUNG = (float) row.optDouble("habOffsetYOUNG", 0);
35 habOffsetAVERAGE = (float) row.optDouble("habOffsetAVERAGE", 0);
36 habOffsetOLD = (float) row.optDouble("habOffsetOLD", 0);
37
38 probOrbits = (float) row.optDouble("probOrbits", 0);
39 minOrbits = (float) row.optDouble("minOrbits", 0);
40 maxOrbits = (float) row.optDouble("maxOrbits", 0);
41
42 for (String key : JSONObject.getNames(row)) {
43 float frequency = (float) row.optDouble(key, 1f);
44 if (frequency != 1) {
45 multipliers.put(key, frequency);
46 }
47 }
48
49 String tags = row.optString("tags", null);
50 if (tags != null) {
51 String [] split = tags.split(",");
52 for (String tag : split) {
53 tag = tag.trim();
54 if (tag.isEmpty()) continue;
55 addTag(tag);
56 }
57 }
58
59 minColor = StarGenDataSpec.parseColor(row.optString("minColor", null) + " 255", " ");
60 maxColor = StarGenDataSpec.parseColor(row.optString("maxColor", null) + " 255", " ");
61 }
62
63 public String toString() {
64 return getId();
65 }
66
67 public String getCategory() {
68 return category;
69 }
70
71 public float getFrequency() {
72 return frequency;
73 }
74
75 public String getId() {
76 return id;
77 }
78
79 public float getHabOffsetMin() {
80 return habOffsetMin;
81 }
82
83 public float getHabOffsetMax() {
84 return habOffsetMax;
85 }
86
87 public float getMinRadius() {
88 return minRadius;
89 }
90
91 public float getMaxRadius() {
92 return maxRadius;
93 }
94
95 public Color getMinColor() {
96 return minColor;
97 }
98
99 public Color getMaxColor() {
100 return maxColor;
101 }
102
103 public float getMultiplier(String key) {
104 if (!multipliers.containsKey(key)) return 1f;
105 return multipliers.get(key);
106 }
107
108 public Set<String> getTags() {
109 return tags;
110 }
111
112 public void addTag(String tag) {
113 tags.add(tag);
114 }
115
116 public boolean hasTag(String tag) {
117 return tags.contains(tag);
118 }
119
120 public Map<String, Float> getMultipliers() {
121 return multipliers;
122 }
123
124 public float getProbOrbits() {
125 return probOrbits;
126 }
127
128 public float getMinOrbits() {
129 return minOrbits;
130 }
131
132 public float getMaxOrbits() {
133 return maxOrbits;
134 }
135
136 public float getHabOffsetYOUNG() {
137 return habOffsetYOUNG;
138 }
139
140 public float getHabOffsetAVERAGE() {
141 return habOffsetAVERAGE;
142 }
143
144 public float getHabOffsetOLD() {
145 return habOffsetOLD;
146 }
147
148}