Starsector API
Loading...
Searching...
No Matches
SimulatorPlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.plugins;
2
3import java.util.ArrayList;
4import java.util.LinkedHashMap;
5import java.util.List;
6import java.util.Map;
7
8import java.awt.Color;
9
10import org.json.JSONException;
11import org.json.JSONObject;
12
13import com.fs.starfarer.api.campaign.BattleAPI;
14import com.fs.starfarer.api.campaign.CampaignFleetAPI;
15import com.fs.starfarer.api.campaign.FactionAPI;
16import com.fs.starfarer.api.combat.DeployedFleetMemberAPI;
17import com.fs.starfarer.api.fleet.FleetMemberAPI;
18import com.fs.starfarer.api.ui.TooltipMakerAPI;
19
28public interface SimulatorPlugin {
29
30 public static boolean ENABLE_OPTION_CHECKBOX_ICONS = true;
31
32 public static float DEFAULT_PAD_AFTER = 20f;
33
34 public static interface AdvancedSimOption {
35 public String getId();
36 public float getPadAfter();
37 }
38
39 public static class SimOptionData {
40 public String id;
41 public String text;
42 public String tooltip;
43 public String iconKey = null;
44 public boolean enabled = true;
45 public String unmetReq = null;
46 public float extraPad = 0f;
47 public SimOptionData(String id, String text, String tooltip, String iconKey) {
48 this.id = id;
49 this.text = text;
50 this.tooltip = tooltip;
52 this.iconKey = iconKey;
53 }
54 }
55 public SimOptionData(String id, String text, String tooltip, boolean enabled, String unmetReq, String iconKey) {
56 super();
57 this.id = id;
58 this.text = text;
59 this.tooltip = tooltip;
60 this.enabled = enabled;
61 this.unmetReq = unmetReq;
63 this.iconKey = iconKey;
64 }
65 }
66 }
67
68 public static class SimOptionSelectorData implements AdvancedSimOption {
69 public String id;
70 public String text;
71 public List<SimOptionData> options = new ArrayList<SimOptionData>();
72 public boolean compact = true;
73 public float padAfter = DEFAULT_PAD_AFTER;
74
75 public SimOptionSelectorData(String id, String text, boolean compact) {
76 this.id = id;
77 this.text = text;
78 this.compact = compact;
79 }
80 public String getId() {
81 return id;
82 }
83 public float getPadAfter() {
84 return padAfter;
85 }
86 }
87
88 public static class SimOptionCheckboxData implements AdvancedSimOption {
89 public String id;
90 public String text;
91 public String tooltip;
92 public boolean showOnOffState = true;
93 public float padAfter = DEFAULT_PAD_AFTER;
94
95 public boolean enabled = true;
96 public String unmetReq = null;
97
98 public SimOptionCheckboxData(String id, String text, String tooltip) {
99 this.id = id;
100 this.text = text;
101 this.tooltip = tooltip;
102 }
103 public SimOptionCheckboxData(String id, String text, String tooltip, boolean enabled, String unmetReq) {
104 this.id = id;
105 this.text = text;
106 this.tooltip = tooltip;
107 this.enabled = enabled;
108 this.unmetReq = unmetReq;
109 }
110 public String getId() {
111 return id;
112 }
113 public float getPadAfter() {
114 return padAfter;
115 }
116 }
117
118
119 public static class SimCategoryData {
120 public String id;
121 public String name;
122 public Color nameColor;
123 public String iconName;
124 public Object data;
125 public boolean custom = false;
126 public boolean nonFactionCategory = false;
127 public FactionAPI faction; // not a real faction, a faked-up copy
128
129 public List<String> variants;
130 public int maxVariants;
131 }
132
133
134 public static class SimUIStateData {
135 public String selectedCategory = null;
136 public boolean showAdvanced = false;
137 public int groupSize;
138 public Map<String, String> settings = new LinkedHashMap<String, String>();
139
140 public void fromJSON(JSONObject json) {
141 selectedCategory = json.optString("selected", null);
142 showAdvanced = json.optBoolean("advanced", false);
143 groupSize = json.optInt("groupSize", 0);
144 settings = new LinkedHashMap<String, String>();
145 JSONObject map = json.optJSONObject("settings");
146 if (map != null) {
147 for (String id : JSONObject.getNames(map)) {
148 String value = map.optString(id, null);
149 if (value != null) {
150 settings.put(id, value);
151 }
152 }
153 }
154 }
155
156 public JSONObject toJSON() throws JSONException {
157 JSONObject json = new JSONObject();
158 if (selectedCategory != null) {
159 json.put("selected", selectedCategory);
160 }
161 json.put("advanced", showAdvanced);
162 json.put("groupSize", groupSize);
163 JSONObject map = new JSONObject();
164 json.put("settings", map);
165 for (String id : settings.keySet()) {
166 map.put(id, (String) settings.get(id));
167 }
168 return json;
169 }
170 }
171
172 public void applySettingsToFleetMembers(List<FleetMemberAPI> members, SimCategoryData category, Map<String, String> settings);
173 public void applySettingsToDeployed(List<DeployedFleetMemberAPI> deployed, Map<String, String> settings);
174
175 public List<SimCategoryData> getCategories();
176 public SimCategoryData getCustomCategory();
177
178 public List<AdvancedSimOption> getSimOptions(SimCategoryData category);
179 public boolean showGroupDeploymentWidget(SimCategoryData category);
180
181 SimUIStateData getUIStateData();
184
185
186 void addCustomOpponents(List<String> variants);
187 void removeCustomOpponents(List<String> variants);
188 //void resetCustomOpponents();
191
192 List<String> generateSelection(SimCategoryData category, int deploymentPoints);
193
194
196
197 void appendToTooltip(TooltipMakerAPI info, float initPad, float width, AdvancedSimOption option, Object extra);
198 void resetToDefaults(boolean withSave);
199
200}
201
202
203
void appendToTooltip(TooltipMakerAPI info, float initPad, float width, AdvancedSimOption option, Object extra)
void reportPlayerBattleOccurred(CampaignFleetAPI primaryWinner, BattleAPI battle)
boolean showGroupDeploymentWidget(SimCategoryData category)
void addCustomOpponents(List< String > variants)
void removeCustomOpponents(List< String > variants)
List< String > generateSelection(SimCategoryData category, int deploymentPoints)
void applySettingsToDeployed(List< DeployedFleetMemberAPI > deployed, Map< String, String > settings)
void applySettingsToFleetMembers(List< FleetMemberAPI > members, SimCategoryData category, Map< String, String > settings)
List< AdvancedSimOption > getSimOptions(SimCategoryData category)
List< SimCategoryData > getCategories()