001package com.fs.starfarer.api.impl.campaign.procgen; 002 003import java.awt.Color; 004import java.util.HashSet; 005import java.util.Set; 006 007import org.json.JSONException; 008import org.json.JSONObject; 009 010import com.fs.starfarer.api.util.Misc; 011 012public class StarGenDataSpec { 013 014 015 //id,starAge,freqYOUNG,freqAVERAGE,freqOLD, 016 //minRadius,maxRadius,coronaMin,coronaMult,coronaVar, 017 //solarWind,minFlare,maxFlare,crLossMult,lightColorMin,lightColorMax 018 019 private String id; 020 private float minRadius, maxRadius, coronaMin, coronaMult, 021 coronaVar, solarWind, minFlare, maxFlare, crLossMult, 022 freqYOUNG, freqAVERAGE, freqOLD; 023 private float probOrbits, minOrbits, maxOrbits, habZoneStart; 024 private Color lightColorMin; 025 private Color lightColorMax; 026 private StarAge age; 027 028 private Set<String> tags = new HashSet<String>(); 029 030 031 public StarGenDataSpec(JSONObject row) throws JSONException { 032 id = row.getString("id"); 033 minRadius = (float) row.getDouble("minRadius"); 034 maxRadius = (float) row.getDouble("maxRadius"); 035 036 coronaMin = (float) row.getDouble("coronaMin"); 037 coronaMult = (float) row.getDouble("coronaMult"); 038 coronaVar = (float) row.getDouble("coronaVar"); 039 040 solarWind = (float) row.getDouble("solarWind"); 041 minFlare = (float) row.getDouble("minFlare"); 042 maxFlare = (float) row.getDouble("maxFlare"); 043 crLossMult = (float) row.getDouble("crLossMult"); 044 045 freqYOUNG = (float) row.getDouble("freqYOUNG"); 046 freqAVERAGE = (float) row.getDouble("freqAVERAGE"); 047 freqOLD = (float) row.getDouble("freqOLD"); 048 049 probOrbits = (float) row.optDouble("probOrbits", 0); 050 minOrbits = (float) row.optDouble("minOrbits", 0); 051 maxOrbits = (float) row.optDouble("maxOrbits", 0); 052 053 habZoneStart = (float) row.optDouble("habZoneStart", 2); 054 055 age = Misc.mapToEnum(row, "age", StarAge.class, StarAge.ANY); 056 057 lightColorMin = parseColor(row.optString("lightColorMin", null) + " 255", " "); 058 lightColorMax = parseColor(row.optString("lightColorMax", null) + " 255", " "); 059 060 String tags = row.optString("tags", null); 061 if (tags != null) { 062 String [] split = tags.split(","); 063 for (String tag : split) { 064 tag = tag.trim(); 065 if (tag.isEmpty()) continue; 066 addTag(tag); 067 } 068 } 069 } 070 071 public static Color parseColor(String str, String sep) { 072 if (str == null) return Color.white; 073 074 String [] parts = str.split(sep); 075 if (parts.length != 4) return Color.white; 076 077 return new Color(Integer.parseInt(parts[0].trim()), 078 Integer.parseInt(parts[1].trim()), 079 Integer.parseInt(parts[2].trim()), 080 Integer.parseInt(parts[3].trim())); 081 } 082 083 public String getId() { 084 return id; 085 } 086 087 088 public float getMinRadius() { 089 return minRadius; 090 } 091 092 093 public float getMaxRadius() { 094 return maxRadius; 095 } 096 097 098 public float getCoronaMin() { 099 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