001package com.fs.starfarer.api.impl.campaign.procgen;
002
003import java.util.HashSet;
004import java.util.Set;
005
006import org.json.JSONException;
007import org.json.JSONObject;
008
009public class NameGenData {
010        
011        public static final String TAG_PLANET = "planet";
012        public static final String TAG_MOON = "moon";
013        public static final String TAG_STAR = "star";
014        public static final String TAG_ASTEROID_BELT = "asteroid_belt";
015        public static final String TAG_ASTEROID_FIELD = "asteroid_field";
016        public static final String TAG_MAGNETIC_FIELD = "magnetic_field";
017        public static final String TAG_RING = "ring";
018        public static final String TAG_ACCRETION = "accretion";
019        public static final String TAG_NEBULA = "nebula";
020        public static final String TAG_CONSTELLATION = "constellation";
021        
022        //      name    secondary       tags    parents
023        
024        private String name, secondary;
025        private float frequency;
026        private boolean reusable;
027        private Set<String> tags = new HashSet<String>();
028        private Set<String> parents = new HashSet<String>();
029        
030        public NameGenData(String name, String secondary) {
031                this.name = name;
032                this.secondary = secondary;
033                this.reusable = false;
034                this.frequency = 1;
035        }
036        
037        public NameGenData(JSONObject row) throws JSONException {
038                name = row.getString("name");
039                secondary = row.optString("secondary");
040                
041                if (name != null) name = name.trim();
042                if (secondary != null) secondary = secondary.trim();
043                
044                frequency = (float) row.optDouble("frequency", 1);
045                reusable = row.optBoolean("reusable", false);
046                
047                if (secondary != null && secondary.isEmpty()) secondary = null;
048                
049                String tags = row.optString("tags", null);
050                if (tags != null) {
051                        String [] split = tags.split(",");
052                        for (String tag : split) {
053                                tag = tag.trim();
054                                if (tag.isEmpty()) continue;
055                                addTag(tag);
056                        }
057                }
058                
059                String parents = row.optString("parents", null);
060                if (parents != null) {
061                        String [] split = parents.split(",");
062                        for (String parent : split) {
063                                parent = parent.trim();
064                                if (parent.isEmpty()) continue;
065                                addParent(parent);
066                        }
067                }
068        }
069
070        public void setTags(Set<String> tags) {
071                this.tags = tags;
072        }
073
074        public Set<String> getTags() {
075                return tags;
076        }
077        
078        public void addTag(String tag) {
079                tags.add(tag);
080        }
081
082        public boolean hasTag(String tag) {
083                return tags.contains(tag);
084        }
085        
086        public void setParents(Set<String> parents) {
087                this.parents = parents;
088        }
089        
090        public Set<String> getParents() {
091                return parents;
092        }
093        
094        public void addParent(String parent) {
095                parents.add(parent);
096        }
097        
098        public boolean hasParent(String parent) {
099                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}