001package com.fs.starfarer.api;
002
003import java.io.IOException;
004import java.io.InputStream;
005import java.util.Collection;
006import java.util.List;
007import java.util.Set;
008
009import java.awt.Color;
010
011import org.json.JSONArray;
012import org.json.JSONException;
013import org.json.JSONObject;
014import org.lwjgl.util.vector.Vector2f;
015
016import com.fs.starfarer.api.campaign.CargoAPI;
017import com.fs.starfarer.api.campaign.CargoAPI.CargoItemType;
018import com.fs.starfarer.api.campaign.CargoStackAPI;
019import com.fs.starfarer.api.campaign.CustomEntitySpecAPI;
020import com.fs.starfarer.api.campaign.CustomUIPanelPlugin;
021import com.fs.starfarer.api.campaign.FactionAPI;
022import com.fs.starfarer.api.campaign.FactionSpecAPI;
023import com.fs.starfarer.api.campaign.LocationAPI;
024import com.fs.starfarer.api.campaign.PlanetSpecAPI;
025import com.fs.starfarer.api.campaign.SectorEntityToken;
026import com.fs.starfarer.api.campaign.SpecialItemSpecAPI;
027import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
028import com.fs.starfarer.api.campaign.econ.MarketAPI;
029import com.fs.starfarer.api.campaign.econ.SubmarketSpecAPI;
030import com.fs.starfarer.api.characters.MarketConditionSpecAPI;
031import com.fs.starfarer.api.characters.PersonAPI;
032import com.fs.starfarer.api.characters.PersonalityAPI;
033import com.fs.starfarer.api.characters.SkillSpecAPI;
034import com.fs.starfarer.api.combat.CombatEntityAPI;
035import com.fs.starfarer.api.combat.CombatReadinessPlugin;
036import com.fs.starfarer.api.combat.ShipAIConfig;
037import com.fs.starfarer.api.combat.ShipAIPlugin;
038import com.fs.starfarer.api.combat.ShipAPI;
039import com.fs.starfarer.api.combat.ShipHullSpecAPI;
040import com.fs.starfarer.api.combat.ShipSystemSpecAPI;
041import com.fs.starfarer.api.combat.ShipVariantAPI;
042import com.fs.starfarer.api.combat.WeaponAPI.WeaponSize;
043import com.fs.starfarer.api.combat.WeaponAPI.WeaponType;
044import com.fs.starfarer.api.fleet.FleetMemberAPI;
045import com.fs.starfarer.api.fleet.FleetMemberType;
046import com.fs.starfarer.api.graphics.SpriteAPI;
047import com.fs.starfarer.api.impl.codex.CodexEntryPlugin;
048import com.fs.starfarer.api.loading.AbilitySpecAPI;
049import com.fs.starfarer.api.loading.BarEventSpec;
050import com.fs.starfarer.api.loading.Description;
051import com.fs.starfarer.api.loading.Description.Type;
052import com.fs.starfarer.api.loading.EventSpecAPI;
053import com.fs.starfarer.api.loading.FighterWingSpecAPI;
054import com.fs.starfarer.api.loading.HullModSpecAPI;
055import com.fs.starfarer.api.loading.IndustrySpecAPI;
056import com.fs.starfarer.api.loading.PersonMissionSpec;
057import com.fs.starfarer.api.loading.RoleEntryAPI;
058import com.fs.starfarer.api.loading.TerrainSpecAPI;
059import com.fs.starfarer.api.loading.WeaponSlotAPI;
060import com.fs.starfarer.api.loading.WeaponSpecAPI;
061import com.fs.starfarer.api.plugins.LevelupPlugin;
062import com.fs.starfarer.api.ui.ButtonAPI;
063import com.fs.starfarer.api.ui.ButtonAPI.UICheckboxSize;
064import com.fs.starfarer.api.ui.CustomPanelAPI;
065import com.fs.starfarer.api.ui.LabelAPI;
066import com.fs.starfarer.api.ui.TextFieldAPI;
067import com.fs.starfarer.api.ui.TooltipMakerAPI;
068import com.fs.starfarer.api.util.ListMap;
069
070/**
071 * @author Alex Mosolov
072 *
073 * Copyright 2012 Fractal Softworks, LLC
074 */
075public interface SettingsAPI {
076        int getBattleSize();
077        
078        boolean isShowingCodex();
079        
080        /**
081         * Can be used outside the campaign, unlike FactoryAPI.createPerson().
082         * @return
083         */
084        PersonAPI createPerson();
085        
086        CargoStackAPI createCargoStack(CargoItemType type, Object data, CargoAPI cargo);
087        
088        LabelAPI createLabel(String text, String font);
089        
090        float getBonusXP(String key);
091        
092        float getFloat(String key);
093        boolean getBoolean(String key);
094        boolean optBoolean(String key, boolean defaultValue);
095        ClassLoader getScriptClassLoader();
096        
097        boolean isCampaignSensorsOn();
098        
099        boolean isDevMode();
100        void setDevMode(boolean devMode);
101        
102        Color getColor(String id);
103        
104        Object getInstanceOfScript(String className);
105        
106        /**
107         * Gets a string from a given category in strings.json
108         * @param category
109         * @param id
110         * @return
111         */
112        String getString(String category, String id);
113        
114        /**
115         * File must already have been loaded. Mostly useful for retrieving ship and weapon sprites and other such.
116         * @param filename
117         * @return
118         */
119        SpriteAPI getSprite(String filename);
120        
121        /**
122         * Gets a sprite loaded using the "graphics" section in data/config/settings.json.
123         * @param category
124         * @param key
125         * @return
126         */
127        SpriteAPI getSprite(String category, String key);
128        
129        /**
130         * Same as the method that takes (String category, String key). SpriteId is just a container class
131         * for category + id.
132         * @param id
133         * @return
134         */
135        SpriteAPI getSprite(SpriteId id);
136        
137        String getSpriteName(String category, String id);
138        
139        /**
140         * Use / instead of \ in paths for compatibility (required to work on OS X and Linux). 
141         * @param filename
142         * @return
143         * @throws IOException
144         */
145        InputStream openStream(String filename) throws IOException;
146        
147        /**
148         * Use / instead of \ in paths for compatibility (required to work on OS X and Linux). 
149         * @param filename
150         * @return
151         * @throws IOException
152         */
153        String loadText(String filename) throws IOException;
154        
155        /**
156         * Use / instead of \ in paths for compatibility (required to work on OS X and Linux). 
157         * @param filename
158         * @return
159         * @throws IOException
160         */
161        JSONObject loadJSON(String filename) throws IOException, JSONException;
162        
163        /**
164         * Returns an array of JSONObjects with keys corresponding to the columns in the csv file.
165         * 
166         * Use / instead of \ in paths for compatibility (required to work on OS X and Linux).
167         * 
168         * @param filename
169         * @return
170         * @throws IOException 
171         * @throws JSONException 
172         */
173        JSONArray loadCSV(String filename) throws IOException, JSONException;
174        
175        /**
176         * Useful for building a mod that allows other mods to override some of its data.
177         * 
178         * Merges on spreadsheet level only; rows with matching ids get replaced by non-master rows.
179         * 
180         * If multiple non-master rows have the same id, one will be picked in an undefined manner.
181         * 
182         * 
183         * @param idColumn the column to be used as the key for merging spreadsheets.
184         * @param path the location of the spreadsheet, i.e. "mydata/spreadsheet.csv".
185         * @param masterMod name of the mod that has the master copy of the spreadsheet, which will be used as the base version to add to/modify during the merge. 
186         * @return
187         * @throws IOException
188         * @throws JSONException
189         */
190        JSONArray getMergedSpreadsheetDataForMod(String idColumn, String path, String masterMod) throws IOException, JSONException;
191        
192        JSONObject getMergedJSONForMod(String path, String masterMod) throws IOException, JSONException;
193        
194        
195        /**
196         * Virtual pixels, i.e. divided by getScreenScaleMult().
197         * @return
198         */
199        float getScreenWidth();
200        
201        /**
202         * Virtual pixels, i.e. divided by getScreenScaleMult().
203         * @return
204         */
205        float getScreenHeight();
206        
207        float getScreenWidthPixels();
208        float getScreenHeightPixels();
209        
210        /**
211         * Gets entry from descriptions.csv. 
212         * @param id
213         * @param type
214         * @return description, or null if not found.
215         */
216        Description getDescription(String id, Type type);
217        
218        CombatReadinessPlugin getCRPlugin();
219        
220        int getCodeFor(String key);
221        
222        
223        
224        
225        WeaponSpecAPI getWeaponSpec(String weaponId);
226
227        void loadTexture(String filename) throws IOException;
228
229        
230        /**
231         * Bit of a hack to have this method here. It's just a way to call into some unexposed utility code.
232         * @param from
233         * @param target
234         * @param considerShield
235         * @return
236         */
237        float getTargetingRadius(Vector2f from, CombatEntityAPI target, boolean considerShield);
238        
239        
240        ShipVariantAPI getVariant(String variantId);
241
242        /**
243         * Plugins returned by this method are cached and persistent across multiple saves. They should not have
244         * any data members that point at campaign data or it will cause a memory leak.
245         * @param id
246         * @return
247         */
248        Object getPlugin(String id);
249
250        List<String> getSortedSkillIds();
251        
252        SkillSpecAPI getSkillSpec(String skillId);
253
254        String getString(String key);
255
256        AbilitySpecAPI getAbilitySpec(String abilityId);
257
258        List<String> getSortedAbilityIds();
259
260        float getBaseTravelSpeed();
261
262        float getSpeedPerBurnLevel();
263
264        float getUnitsPerLightYear();
265
266        int getMaxShipsInFleet();
267
268        TerrainSpecAPI getTerrainSpec(String terrainId);
269        EventSpecAPI getEventSpec(String eventId);
270        CustomEntitySpecAPI getCustomEntitySpec(String id);
271
272        GameState getCurrentState();
273
274        int getMaxSensorRange();
275        int getMaxSensorRangeHyper();
276        int getMaxSensorRange(LocationAPI loc);
277
278        List<String> getAllVariantIds();
279        List<String> getAptitudeIds();
280        List<String> getSkillIds();
281        LevelupPlugin getLevelupPlugin();
282        String getVersionString();
283
284        JSONObject loadJSON(String filename, String modId) throws IOException, JSONException;
285        JSONArray loadCSV(String filename, String modId) throws IOException, JSONException;
286        String loadText(String filename, String modId) throws IOException, JSONException;
287
288        ModManagerAPI getModManager();
289
290        float getBaseFleetSelectionRadius();
291        float getFleetSelectionRadiusPerUnitSize();
292        float getMaxFleetSelectionRadius();
293
294        List<RoleEntryAPI> getEntriesForRole(String factionId, String role);
295        void addEntryForRole(String factionId, String role, String variantId, float weight);
296        void removeEntryForRole(String factionId, String role, String variantId);
297
298        List<RoleEntryAPI> getDefaultEntriesForRole(String role);
299        void addDefaultEntryForRole(String role, String variantId, float weight);
300        void removeDefaultEntryForRole(String role, String variantId);
301
302        void profilerBegin(String id);
303        void profilerEnd();
304        void profilerPrintResultsTree();
305
306        List<PlanetSpecAPI> getAllPlanetSpecs();
307
308        Object getSpec(Class c, String id, boolean nullOnNotFound);
309        void putSpec(Class c, String id, Object spec);
310        <T> Collection<T> getAllSpecs(Class<T> c);
311
312        /**
313         * @param n 1 to 3999.
314         * @return
315         */
316        String getRoman(int n);
317        void greekLetterReset();
318        String getNextCoolGreekLetter(Object context);
319        String getNextGreekLetter(Object context);
320
321        MarketConditionSpecAPI getMarketConditionSpec(String conditionId);
322        
323        
324        ShipAIPlugin createDefaultShipAI(ShipAPI ship, ShipAIConfig config);
325
326        HullModSpecAPI getHullModSpec(String modId);
327        FighterWingSpecAPI getFighterWingSpec(String wingId);
328        List<HullModSpecAPI> getAllHullModSpecs();
329        List<FighterWingSpecAPI> getAllFighterWingSpecs();
330
331        List<WeaponSpecAPI> getAllWeaponSpecs();
332        /**
333         * Includes SYSTEM weapons and, well, everything.
334         * @return
335         */
336        List<WeaponSpecAPI> getActuallyAllWeaponSpecs();
337
338        boolean isSoundEnabled();
339
340        boolean isInCampaignState();
341
342        boolean isGeneratingNewGame();
343
344        float getAngleInDegreesFast(Vector2f v);
345        float getAngleInDegreesFast(Vector2f from, Vector2f to);
346
347        CommoditySpecAPI getCommoditySpec(String commodityId);
348
349        ShipHullSpecAPI getHullSpec(String hullId);
350        
351        FactionSpecAPI getFactionSpec(String id);
352
353        int computeNumFighterBays(ShipVariantAPI variant);
354
355        
356        /**
357         * For modding purposes, always returns true.
358         * @return
359         */
360        boolean isInGame();
361
362        Object getNewPluginInstance(String id);
363        String getControlStringForAbilitySlot(int index);
364
365        
366        /**
367         * Total hack instead of moving the Controls enum out to the .api project. Use at own peril.
368         * @param name
369         * @return
370         */
371        String getControlStringForEnumName(String name);
372
373        boolean isNewPlayer();
374
375        IndustrySpecAPI getIndustrySpec(String industryId);
376
377        List<CommoditySpecAPI> getAllCommoditySpecs();
378
379        int getInt(String key);
380
381        List<IndustrySpecAPI> getAllIndustrySpecs();
382
383        SpecialItemSpecAPI getSpecialItemSpec(String itemId);
384
385        List<SpecialItemSpecAPI> getAllSpecialItemSpecs();
386
387        List<ShipHullSpecAPI> getAllShipHullSpecs();
388
389        SpriteAPI getSprite(String category, String id, boolean emptySpriteOnNotFound);
390
391        ShipVariantAPI createEmptyVariant(String hullVariantId, ShipHullSpecAPI hullSpec);
392
393        /**
394         * For default ship roles.
395         * @return
396         */
397        ListMap<String> getHullIdToVariantListMap();
398
399        
400        
401        String readTextFileFromCommon(String filename) throws IOException;
402        
403        /**
404         * Max size 1mb.
405         * @param filename
406         * @param data
407         * @throws IOException
408         */
409        void writeTextFileToCommon(String filename, String data) throws IOException;
410
411        boolean fileExistsInCommon(String filename);
412        void deleteTextFileFromCommon(String filename);
413        
414        Color getBasePlayerColor();
415        Color getDesignTypeColor(String designType);
416
417        boolean doesVariantExist(String variantId);
418
419        void addCommodityInfoToTooltip(TooltipMakerAPI tooltip, float initPad, CommoditySpecAPI spec, 
420                                                                   int max, boolean withText, boolean withSell, boolean withBuy);
421
422        
423        JSONObject getJSONObject(String key) throws JSONException;
424        JSONArray getJSONArray(String key) throws JSONException;
425
426        /**
427         * Should be used when faction data needs to be accessed outside the campaign.
428         * @param factionId
429         * @return
430         */
431        FactionAPI createBaseFaction(String factionId);
432
433        List<MarketConditionSpecAPI> getAllMarketConditionSpecs();
434        List<SubmarketSpecAPI> getAllSubmarketSpecs();
435
436        float getMinArmorFraction();
437
438        float getMaxArmorDamageReduction();
439
440        ShipSystemSpecAPI getShipSystemSpec(String id);
441        List<ShipSystemSpecAPI> getAllShipSystemSpecs();
442
443        float getScreenScaleMult();
444        int getAASamples();
445
446        /**
447         * Converted to virtual screen coordinates, i.e. adjusted for screen scaling.
448         * @return
449         */
450        int getMouseX();
451        
452        /**
453         * Converted to virtual screen coordinates, i.e. adjusted for screen scaling.
454         * @return
455         */
456        int getMouseY();
457
458        int getShippingCapacity(MarketAPI market, boolean inFaction);
459        JSONObject getSettingsJSON();
460        /**
461         * Must be called after making any changes to result of getSettingsJSON().
462         */
463        void resetCached();
464
465        void setFloat(String key, Float value);
466        void setBoolean(String key, Boolean value);
467
468        List<PersonMissionSpec> getAllMissionSpecs();
469        PersonMissionSpec getMissionSpec(String id);
470        
471        List<BarEventSpec> getAllBarEventSpecs();
472        BarEventSpec getBarEventSpec(String id);
473
474        void setAutoTurnMode(boolean autoTurnMode);
475        boolean isAutoTurnMode();
476
477        boolean isShowDamageFloaties();
478
479        float getFloatFromArray(String key, int index);
480
481        int getIntFromArray(String key, int index);
482
483        void loadTextureConvertBlackToAlpha(String filename) throws IOException;
484
485        String getControlDescriptionForEnumName(String name);
486
487        ShipAIPlugin pickShipAIPlugin(FleetMemberAPI member, ShipAPI ship);
488
489        void unloadTexture(String filename);
490
491        void profilerSetEnabled(boolean enabled);
492
493        void profilerReset();
494
495        void profilerRestore();
496
497        Color getBrightPlayerColor();
498
499        Color getDarkPlayerColor();
500
501        void forceMipmapsFor(String filename, boolean forceMipmaps) throws IOException;
502
503        /**
504         * Returns e.g. "0.95a-RC12"
505         * @return
506         */
507        String getGameVersion();
508
509        float computeStringWidth(String in, String font);
510
511        TextFieldAPI createTextField(String text, String font);
512
513        ButtonAPI createCheckbox(String text, UICheckboxSize size);
514        ButtonAPI createCheckbox(String text, String font, Color checkColor, UICheckboxSize size);
515
516        CustomPanelAPI createCustom(float width, float height, CustomUIPanelPlugin plugin);
517
518        int getMissionScore(String id);
519
520        WeaponSlotAPI createWeaponSlot(String id, WeaponType weaponType, WeaponSize slotSize, String slotTypeStr,
521                                                                   String nodeId, Vector2f nodePos, float angle, float arc);
522
523        JSONArray getMergedSpreadsheetData(String idColumn, String path) throws IOException, JSONException;
524        JSONObject getMergedJSON(String path) throws IOException, JSONException;
525
526        void setEasySensorBonus(float easySensorBonus);
527
528        boolean isEnableShipExplosionWhiteout();
529        void setEnableShipExplosionWhiteout(boolean enableShipExplosionWhiteout);
530
531        List<WeaponSpecAPI> getSystemWeaponSpecs();
532
533        List<String> getSpriteKeys(String category);
534        List<String> getSpriteKeys(String category, String listId);
535
536        JSONObject loadJSON(String filename, boolean withMods) throws IOException, JSONException;
537        JSONArray loadCSV(String filename, boolean withMods) throws IOException, JSONException;
538
539        float getSensorRangeMaxHyper();
540        float getSensorRangeMax();
541
542        void loadFont(String filename) throws IOException;
543
544        boolean isStrafeKeyAToggle();
545
546        List<FactionSpecAPI> getAllFactionSpecs();
547
548        PersonalityAPI getPersonaltySpec(String id);
549
550        /**
551         * @param onlyIfChanged should be used sparingly, for something where the file size
552         * is fairly small and the writes are common/time sensitive. If true, the write will
553         * also happen on a new thread.
554         * Can cause increased memory use if overused for large files.
555         */
556        void writeJSONToCommon(String filename, JSONObject json, boolean onlyIfChanged) throws IOException, JSONException;
557        
558        /**
559         * @param putInWriteCache should only be set to true for files you intend to call writeJSONToCommon() for
560         * with onlyIfChanged == true. Otherwise, causes unnecessary memory use.
561         */
562        JSONObject readJSONFromCommon(String filename, boolean putInWriteCache) throws IOException, JSONException;
563
564        List<String> getSimOpponents();
565        List<String> getSimOpponentsDev();
566        
567        /**
568         * @return Set of commodity ids, no quantity information.
569         */
570        Set<String> getIndustrySupply(String industryId);
571        
572        /**
573         * @return Set of commodity ids, no quantity information.
574         */
575        Set<String> getIndustryDemand(String industryId);
576        
577        
578        /**
579         * Can be called from anywhere. Will do nothing if the Codex is already open.
580         * @param entryId
581         */
582        void showCodex(String entryId);
583        void showCodex(CodexEntryPlugin tempEntry);
584        
585        /**
586         * Will show the first entry, but will add all of the entries temporarily, until the Codex is closed.
587         * @param tempEntries
588         */
589        void showCodex(List<CodexEntryPlugin> tempEntries);
590        void showCodex(FleetMemberAPI member); 
591        
592        FleetMemberAPI createFleetMember(FleetMemberType type, String variantOrWingId);
593        FleetMemberAPI createFleetMember(FleetMemberType type, ShipVariantAPI variant);
594        
595        List<TerrainSpecAPI> getAllTerrainSpecs();
596        SectorEntityToken createLocationToken(float x, float y);
597        boolean hasDesignTypeColor(String designType);
598        
599        public float getFriendlyFireDanger(ShipAPI shooter, CombatEntityAPI target,
600                          Vector2f from, Vector2f to,
601                          float weaponSpeed, float burstFireDuration, float weaponRange);
602        public float getSafeMovementDir(ShipAPI ship);
603}
604
605