001package com.fs.starfarer.api; 002 003import org.apache.log4j.Logger; 004 005import com.fs.starfarer.api.campaign.SectorAPI; 006import com.fs.starfarer.api.combat.CombatEngineAPI; 007import org.jetbrains.annotations.NotNull; 008import org.jetbrains.annotations.Nullable; 009 010 /** 011 * The primary way to access most of the game's state (fleets, stars, ships, people, etc) and many useful classes for creating and modifying state. 012 * 013 * @author Alex Mosolov 014 * 015 * Copyright 2012 Fractal Softworks, LLC 016 */ 017public class Global { 018 019 public static boolean CODEX_TOOLTIP_MODE = false; 020 021 public static boolean LOADING_SAVE = false; 022 023 024 private static SettingsAPI settingsAPI; 025 private static SectorAPI sectorAPI; 026 private static FactoryAPI factory; 027 private static SoundPlayerAPI soundPlayer; 028 private static CombatEngineAPI combatEngine; 029 030 031 public static GameState getCurrentState() { 032 return settingsAPI.getCurrentState(); 033 } 034 035 /** 036 * Creates a new {@link Logger} that will add the given class to all log messages it produces. 037 * <pre> 038 * {@code 039 * class MyClass { 040 * Logger log = Global.getLogger(MyClass.class); 041 * 042 * void myMethod() { 043 * log.info("Hello, world!"); 044 * } 045 * } 046 *} 047 * </pre> 048 * 049 * @param c the class to add to the log messages 050 */ 051 @SuppressWarnings("unchecked") 052 public static Logger getLogger(Class c) { 053 Logger log = Logger.getLogger(c); 054 return log; 055 } 056 057 /** 058 * Used to create fleets, markets, cargo, crew compositions, jump points, progress indicators, 059 * memory objects, persons, officer data, battles, cargo stacks, communication messages, fleet stubs, 060 * and fleet AI, along with various orbit configurations and fleet members. 061 * 062 * Should only be used in the campaign. 063 */ 064 public static FactoryAPI getFactory() { 065 return factory; 066 } 067 068 public static void setFactory(FactoryAPI factory) { 069 Global.factory = factory; 070 } 071 072 /** 073 * Gets the {@link SoundPlayerAPI}, which is used to play sound effects and music. 074 */ 075 public static SoundPlayerAPI getSoundPlayer() { 076 return soundPlayer; 077 } 078 079 public static void setSoundPlayer(SoundPlayerAPI sound) { 080 Global.soundPlayer = sound; 081 } 082 083 /** 084 * Gets the {@link SettingsAPI}, which contains access to current settings and many useful utility methods. 085 */ 086 @NotNull 087 public static SettingsAPI getSettings() { 088 return settingsAPI; 089 } 090 091 public static void setSettings(SettingsAPI api) { 092 Global.settingsAPI = api; 093 } 094 095 /** 096 * Gets the currently loaded save game's {@link SectorAPI}, which contains all {@link com.fs.starfarer.api.campaign.StarSystemAPI}s, 097 * {@link com.fs.starfarer.api.fleet.FleetAPI}s, the sectory {@link com.fs.starfarer.api.campaign.rules.MemoryAPI}, and more. 098 * <p> 099 * On the main menu, this may or may not be null. 100 */ 101 @Nullable 102 public static SectorAPI getSector() { 103 return sectorAPI; 104 } 105 106 /** 107 * Gets the {@link CombatEngineAPI}, which is typically active in combat, on the main menu, and on the refit screen. 108 * Mainly used to get info about and modify battles. 109 */ 110 public static CombatEngineAPI getCombatEngine() { 111 return combatEngine; 112 } 113 114 public static void setCombatEngine(CombatEngineAPI combatEngine) { 115 Global.combatEngine = combatEngine; 116 } 117 118 public static void setSector(SectorAPI api) { 119 Global.sectorAPI = api; 120 } 121 122 /** 123 * @deprecated use {@link #getSettings()} instead 124 */ 125 @Deprecated 126 public static SettingsAPI getSettingsAPI() { 127 return settingsAPI; 128 } 129 130 /** 131 * @deprecated use {@link #getSector()} instead 132 */ 133 @Deprecated 134 public static SectorAPI getSectorAPI() { 135 return sectorAPI; 136 } 137}