Starsector API
Loading...
Searching...
No Matches
BarEventSpec.java
Go to the documentation of this file.
1package com.fs.starfarer.api.loading;
2
3import java.util.HashSet;
4import java.util.Set;
5
6import org.json.JSONException;
7import org.json.JSONObject;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.impl.campaign.intel.bar.PortsideBarEvent;
11import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithBarEvent;
12
13public class BarEventSpec {
14
15 //bar event id,tags,freq,prob,
16 //min dur,max dur,min timeout,max timeout,min accepted timeout,max accepted timeout,plugin
17
18 protected String id;
19 protected Set<String> tags = new HashSet<String>();
20
21 protected float freq;
22 protected float prob;
23 protected float minDur;
24 protected float maxDur;
25 protected float minTimeout;
26 protected float maxTimeout;
27 protected float minAcceptedTimeout;
28 protected float maxAcceptedTimeout;
29
30 protected String pluginClass;
31
32
33 public BarEventSpec(JSONObject row) throws JSONException {
34
35 id = row.getString("bar event id");
36
37 freq = (float)row.optDouble("freq", 10f);
38 prob = (float)row.optDouble("prob", 1f);
39
40 minDur = (float)row.optDouble("min dur", 30f);
41 maxDur = (float)row.optDouble("max dur", 40f);
42 minTimeout = (float)row.optDouble("min timeout", 30f);
43 maxTimeout = (float)row.optDouble("max timeout", 40f);
44 minAcceptedTimeout = (float)row.optDouble("min accepted timeout", 60f);
45 maxAcceptedTimeout = (float)row.optDouble("max accepted timeout", 90f);
46
47 pluginClass = row.getString("plugin");
48
49 String tagsStr = row.optString("tags", null);
50 if (tagsStr != null) {
51 String [] split = tagsStr.split(",");
52 for (String tag : split) {
53 tag = tag.trim();
54 if (tag.isEmpty()) continue;
55 tags.add(tag);
56 }
57 }
58 }
59
60
61 public boolean isMission() {
62 return Global.getSettings().getInstanceOfScript(pluginClass) instanceof HubMissionWithBarEvent;
63 }
64
65 public HubMissionWithBarEvent createMission() {
66 HubMissionWithBarEvent mission = (HubMissionWithBarEvent) Global.getSettings().getInstanceOfScript(pluginClass);
68 if (spec != null && spec.getIcon() != null) {
69 mission.setIconName(spec.getIcon());
70 }
71 mission.setMissionId(id);
72 return mission;
73 }
74
75 public PortsideBarEvent createEvent() {
76 PortsideBarEvent event = (PortsideBarEvent) Global.getSettings().getInstanceOfScript(pluginClass);
77 return event;
78 }
79
80 public Set<String> getTags() {
81 return tags;
82 }
83
84 public void addTag(String tag) {
85 tags.add(tag);
86 }
87
88 public boolean hasTag(String tag) {
89 return tags.contains(tag);
90 }
91
92 public String getId() {
93 return id;
94 }
95
96 public void setId(String id) {
97 this.id = id;
98 }
99
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
153 this.minAcceptedTimeout = minAcceptedTimeout;
154 }
155
156 public float getMaxAcceptedTimeout() {
157 return maxAcceptedTimeout;
158 }
159
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
static SettingsAPI getSettings()
Definition Global.java:51
void setMaxAcceptedTimeout(float maxAcceptedTimeout)
void setMinAcceptedTimeout(float minAcceptedTimeout)
Object getInstanceOfScript(String className)
PersonMissionSpec getMissionSpec(String id)