001package com.fs.starfarer.api.plugins;
002
003import java.util.ArrayList;
004import java.util.LinkedHashMap;
005import java.util.List;
006import java.util.Map;
007
008import java.awt.Color;
009
010import org.json.JSONException;
011import org.json.JSONObject;
012
013import com.fs.starfarer.api.campaign.BattleAPI;
014import com.fs.starfarer.api.campaign.CampaignFleetAPI;
015import com.fs.starfarer.api.campaign.FactionAPI;
016import com.fs.starfarer.api.combat.DeployedFleetMemberAPI;
017import com.fs.starfarer.api.fleet.FleetMemberAPI;
018import com.fs.starfarer.api.ui.TooltipMakerAPI;
019
020/**
021 * Implementations of this need to handle some campaign events but to also work outside the campaign,
022 * e.g. for the devMode "edit variants" simulator, and for the mission refit simulator.
023 * 
024 * @author Alex
025 *
026 * Copyright 2024 Fractal Softworks, LLC
027 */
028public interface SimulatorPlugin {
029
030        public static boolean ENABLE_OPTION_CHECKBOX_ICONS = true;
031        
032        public static float DEFAULT_PAD_AFTER = 20f;
033        
034        public static interface AdvancedSimOption {
035                public String getId();
036                public float getPadAfter();
037        }
038        
039        public static class SimOptionData {
040                public String id;
041                public String text;
042                public String tooltip;
043                public String iconKey = null;
044                public boolean enabled = true;
045                public String unmetReq = null;
046                public float extraPad = 0f;
047                public SimOptionData(String id, String text, String tooltip, String iconKey) {
048                        this.id = id;
049                        this.text = text;
050                        this.tooltip = tooltip;
051                        if (ENABLE_OPTION_CHECKBOX_ICONS) {
052                                this.iconKey = iconKey;
053                        }
054                }
055                public SimOptionData(String id, String text, String tooltip, boolean enabled, String unmetReq, String iconKey) {
056                        super();
057                        this.id = id;
058                        this.text = text;
059                        this.tooltip = tooltip;
060                        this.enabled = enabled;
061                        this.unmetReq = unmetReq;
062                        if (ENABLE_OPTION_CHECKBOX_ICONS) {
063                                this.iconKey = iconKey;
064                        }
065                }
066        }
067        
068        public static class SimOptionSelectorData implements AdvancedSimOption {
069                public String id;
070                public String text;
071                public List<SimOptionData> options = new ArrayList<SimOptionData>();
072                public boolean compact = true;
073                public float padAfter = DEFAULT_PAD_AFTER;
074
075                public SimOptionSelectorData(String id, String text, boolean compact) {
076                        this.id = id;
077                        this.text = text;
078                        this.compact = compact;
079                }
080                public String getId() {
081                        return id;
082                }
083                public float getPadAfter() {
084                        return padAfter;
085                }
086        }
087        
088        public static class SimOptionCheckboxData implements AdvancedSimOption {
089                public String id;
090                public String text;
091                public String tooltip;
092                public boolean showOnOffState = true;
093                public float padAfter = DEFAULT_PAD_AFTER;
094                
095                public boolean enabled = true;
096                public String unmetReq = null;
097                
098                public SimOptionCheckboxData(String id, String text, String tooltip) {
099                        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();
182        void loadUIStateData();
183        void saveUIStateData();
184        
185
186        void addCustomOpponents(List<String> variants);
187        void removeCustomOpponents(List<String> variants);
188        //void resetCustomOpponents();
189        void loadCustomOpponents();
190        void saveCustomOpponents();
191
192        List<String> generateSelection(SimCategoryData category, int deploymentPoints);
193
194        
195        void reportPlayerBattleOccurred(CampaignFleetAPI primaryWinner, BattleAPI battle);
196
197        void appendToTooltip(TooltipMakerAPI info, float initPad, float width, AdvancedSimOption option, Object extra);
198        void resetToDefaults(boolean withSave);
199
200}
201
202
203