Starsector API
Loading...
Searching...
No Matches
NameGenData.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen;
2
3import java.util.HashSet;
4import java.util.Set;
5
6import org.json.JSONException;
7import org.json.JSONObject;
8
9public class NameGenData {
10
11 public static final String TAG_PLANET = "planet";
12 public static final String TAG_MOON = "moon";
13 public static final String TAG_STAR = "star";
14 public static final String TAG_ASTEROID_BELT = "asteroid_belt";
15 public static final String TAG_ASTEROID_FIELD = "asteroid_field";
16 public static final String TAG_MAGNETIC_FIELD = "magnetic_field";
17 public static final String TAG_RING = "ring";
18 public static final String TAG_ACCRETION = "accretion";
19 public static final String TAG_NEBULA = "nebula";
20 public static final String TAG_CONSTELLATION = "constellation";
21
22 // name secondary tags parents
23
24 private String name, secondary;
25 private float frequency;
26 private boolean reusable;
27 private Set<String> tags = new HashSet<String>();
28 private Set<String> parents = new HashSet<String>();
29
30 public NameGenData(String name, String secondary) {
31 this.name = name;
32 this.secondary = secondary;
33 this.reusable = false;
34 this.frequency = 1;
35 }
36
37 public NameGenData(JSONObject row) throws JSONException {
38 name = row.getString("name");
39 secondary = row.optString("secondary");
40
41 if (name != null) name = name.trim();
42 if (secondary != null) secondary = secondary.trim();
43
44 frequency = (float) row.optDouble("frequency", 1);
45 reusable = row.optBoolean("reusable", false);
46
47 if (secondary != null && secondary.isEmpty()) secondary = null;
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 String parents = row.optString("parents", null);
60 if (parents != null) {
61 String [] split = parents.split(",");
62 for (String parent : split) {
63 parent = parent.trim();
64 if (parent.isEmpty()) continue;
65 addParent(parent);
66 }
67 }
68 }
69
70 public void setTags(Set<String> tags) {
71 this.tags = tags;
72 }
73
74 public Set<String> getTags() {
75 return tags;
76 }
77
78 public void addTag(String tag) {
79 tags.add(tag);
80 }
81
82 public boolean hasTag(String tag) {
83 return tags.contains(tag);
84 }
85
86 public void setParents(Set<String> parents) {
87 this.parents = parents;
88 }
89
90 public Set<String> getParents() {
91 return parents;
92 }
93
94 public void addParent(String parent) {
95 parents.add(parent);
96 }
97
98 public boolean hasParent(String parent) {
99 return parents.contains(parent);
100 }
101
102 public String getName() {
103 return name;
104 }
105
106 public void setName(String name) {
107 this.name = name;
108 }
109
110 public String getSecondary() {
111 return secondary;
112 }
113
114 public void setSecondary(String secondary) {
115 this.secondary = secondary;
116 }
117
118 public float getFrequency() {
119 return frequency;
120 }
121
122 public void setFrequency(float frequency) {
123 this.frequency = frequency;
124 }
125
126 public boolean isReusable() {
127 return reusable;
128 }
129
130 public void setReusable(boolean reusable) {
131 this.reusable = reusable;
132 }
133
134
135
136}