001package com.fs.starfarer.api.loading;
002
003import java.util.HashSet;
004import java.util.Set;
005
006import org.json.JSONException;
007import org.json.JSONObject;
008
009import com.fs.starfarer.api.Global;
010import com.fs.starfarer.api.impl.campaign.intel.bar.PortsideBarEvent;
011import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithBarEvent;
012
013public class BarEventSpec {
014        
015        //bar event id,tags,freq,prob,
016        //min dur,max dur,min timeout,max timeout,min accepted timeout,max accepted timeout,plugin
017        
018        protected String id;
019        protected Set<String> tags = new HashSet<String>();
020        
021        protected float freq;
022        protected float prob;
023        protected float minDur;
024        protected float maxDur;
025        protected float minTimeout;
026        protected float maxTimeout;
027        protected float minAcceptedTimeout;
028        protected float maxAcceptedTimeout;
029        
030        protected String pluginClass;
031        
032        
033        public BarEventSpec(JSONObject row) throws JSONException {
034                
035                id = row.getString("bar event id");
036                
037                freq = (float)row.optDouble("freq", 10f);
038                prob = (float)row.optDouble("prob", 1f);
039                
040                minDur = (float)row.optDouble("min dur", 30f);
041                maxDur = (float)row.optDouble("max dur", 40f);
042                minTimeout = (float)row.optDouble("min timeout", 30f);
043                maxTimeout = (float)row.optDouble("max timeout", 40f);
044                minAcceptedTimeout = (float)row.optDouble("min accepted timeout", 60f);
045                maxAcceptedTimeout = (float)row.optDouble("max accepted timeout", 90f);
046                
047                pluginClass = row.getString("plugin");
048                
049                String tagsStr = row.optString("tags", null);
050                if (tagsStr != null) {
051                        String [] split = tagsStr.split(",");
052                        for (String tag : split) {
053                                tag = tag.trim();
054                                if (tag.isEmpty()) continue;
055                                tags.add(tag);
056                        }
057                }
058        }
059
060        
061        public boolean isMission() {
062                return Global.getSettings().getInstanceOfScript(pluginClass) instanceof HubMissionWithBarEvent;
063        }
064        
065        public HubMissionWithBarEvent createMission() {
066                HubMissionWithBarEvent mission = (HubMissionWithBarEvent) Global.getSettings().getInstanceOfScript(pluginClass);
067                PersonMissionSpec spec = Global.getSettings().getMissionSpec(id);
068                if (spec != null && spec.getIcon() != null) {
069                        mission.setIconName(spec.getIcon());
070                }
071                mission.setMissionId(id);
072                return mission;
073        }
074        
075        public PortsideBarEvent createEvent() {
076                PortsideBarEvent event = (PortsideBarEvent) Global.getSettings().getInstanceOfScript(pluginClass);
077                return event;
078        }
079        
080        public Set<String> getTags() {
081                return tags;
082        }
083        
084        public void addTag(String tag) {
085                tags.add(tag);
086        }
087
088        public boolean hasTag(String tag) {
089                return tags.contains(tag);
090        }
091
092        public String getId() {
093                return id;
094        }
095
096        public void setId(String id) {
097                this.id = id;
098        }
099
100        public float getFreq() {
101                return freq;
102        }
103
104        public void setFreq(float freq) {
105                this.freq = freq;
106        }
107
108        public float getProb() {
109                return prob;
110        }
111
112        public void setProb(float prob) {
113                this.prob = prob;
114        }
115
116        public float getMinDur() {
117                return minDur;
118        }
119
120        public void setMinDur(float minDur) {
121                this.minDur = minDur;
122        }
123
124        public float getMaxDur() {
125                return maxDur;
126        }
127
128        public void setMaxDur(float maxDur) {
129                this.maxDur = maxDur;
130        }
131
132        public float getMinTimeout() {
133                return minTimeout;
134        }
135
136        public void setMinTimeout(float minTimeout) {
137                this.minTimeout = minTimeout;
138        }
139
140        public float getMaxTimeout() {
141                return maxTimeout;
142        }
143
144        public void setMaxTimeout(float maxTimeout) {
145                this.maxTimeout = maxTimeout;
146        }
147
148        public float getMinAcceptedTimeout() {
149                return minAcceptedTimeout;
150        }
151
152        public void setMinAcceptedTimeout(float minAcceptedTimeout) {
153                this.minAcceptedTimeout = minAcceptedTimeout;
154        }
155
156        public float getMaxAcceptedTimeout() {
157                return maxAcceptedTimeout;
158        }
159
160        public void setMaxAcceptedTimeout(float maxAcceptedTimeout) {
161                this.maxAcceptedTimeout = maxAcceptedTimeout;
162        }
163
164        public String getPluginClass() {
165                return pluginClass;
166        }
167
168        public void setPluginClass(String pluginClass) {
169                this.pluginClass = pluginClass;
170        }
171        
172        
173}
174
175
176
177
178
179