gdx-studio
git clone https://git.pyrossh.dev/gdx-studio
An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop
src/scene2d/Config.java
| a9b2a64 | 1 | package scene2d; |
| a62d533 | 2 | import com.badlogic.gdx.Gdx; |
| a62d533 | 3 | import com.badlogic.gdx.Preferences; |
| a62d533 | 4 | |
| a62d533 | 5 | /** The Configuration/Settings for the Game |
| a62d533 | 6 | * <p> |
| a62d533 | 7 | * The Config class contains all the necessary options for all different platforms into one class. |
| a62d533 | 8 | * Here you can save all the data of the game that is required to be persistent.<br> |
| a62d533 | 9 | * @author pyros2097 */ |
| a62d533 | 10 | |
| a62d533 | 11 | public final class Config {
|
| a62d533 | 12 | static final String MUSIC = "music"; |
| a62d533 | 13 | static final String SOUND = "sound"; |
| a62d533 | 14 | static final String VOLUME_MUSIC = "volumeMusic"; |
| a62d533 | 15 | static final String VOLUME_SOUND = "volumeSOUND"; |
| a62d533 | 16 | static final String VIBRATION = "vibration"; |
| a62d533 | 17 | static final String BATTLE_ANIMATION = "battleanimation"; |
| a62d533 | 18 | static final String SEMI_AUTOMATIC = "semiautomatic"; |
| a62d533 | 19 | static final String FIRST_LAUNCH = "firstLaunch"; |
| a62d533 | 20 | static final String LEVELS = "levels"; |
| a62d533 | 21 | static final String CURRENT_LEVEL = "currentlevel"; |
| a62d533 | 22 | static final String SAVEDATA= "savedata"; |
| a62d533 | 23 | static final String TOTAL_TIME= "totaltime"; |
| a62d533 | 24 | static final String PANSPEED = "panspeed"; |
| a62d533 | 25 | static final String DRAGSPEED = "dragspeed"; |
| a62d533 | 26 | static final String KEYBOARD = "keyboard"; |
| a62d533 | 27 | static final String SCORE = "score"; |
| a62d533 | 28 | |
| a62d533 | 29 | public static Preferences prefs; |
| a62d533 | 30 | |
| a62d533 | 31 | public static boolean isMusic; |
| a62d533 | 32 | public static boolean isSound; |
| a62d533 | 33 | |
| a62d533 | 34 | public static float volMusic; |
| a62d533 | 35 | public static float volSound; |
| a62d533 | 36 | |
| a62d533 | 37 | public static boolean useKeyboard; |
| a62d533 | 38 | |
| a62d533 | 39 | public static float speedPan; |
| a62d533 | 40 | public static float speedDrag; |
| a62d533 | 41 | |
| a62d533 | 42 | private static int score; |
| a62d533 | 43 | |
| a62d533 | 44 | static void setup(){
|
| a9b2a64 | 45 | prefs = Gdx.app.getPreferences(Scene.configJson.getString("title"));
|
| a62d533 | 46 | isMusic = prefs.getBoolean(MUSIC, true); |
| a62d533 | 47 | isSound = prefs.getBoolean(SOUND, true); |
| a62d533 | 48 | |
| a62d533 | 49 | volMusic = prefs.getFloat(VOLUME_MUSIC, 1f); |
| a62d533 | 50 | volSound = prefs.getFloat(VOLUME_SOUND, 1f); |
| a62d533 | 51 | |
| a62d533 | 52 | useKeyboard = prefs.getBoolean(KEYBOARD, true); |
| a62d533 | 53 | |
| a62d533 | 54 | speedPan = prefs.getFloat(PANSPEED, 5f); |
| a62d533 | 55 | speedDrag = prefs.getFloat(DRAGSPEED, 5f); |
| a62d533 | 56 | |
| a62d533 | 57 | score = prefs.getInteger(SCORE, 0); |
| a62d533 | 58 | } |
| a62d533 | 59 | |
| a62d533 | 60 | |
| a62d533 | 61 | |
| a62d533 | 62 | public static String readSaveData(){
|
| a62d533 | 63 | return prefs.getString(SAVEDATA, "nodata"); |
| a62d533 | 64 | } |
| a62d533 | 65 | |
| a62d533 | 66 | public static void writeSaveData(String ue){
|
| a62d533 | 67 | prefs.putString(SAVEDATA, ue); |
| a62d533 | 68 | prefs.flush(); |
| a62d533 | 69 | } |
| a62d533 | 70 | |
| a62d533 | 71 | public static float readTotalTime(){
|
| a62d533 | 72 | return prefs.getFloat(TOTAL_TIME, 0.0f); |
| a62d533 | 73 | } |
| a62d533 | 74 | |
| a62d533 | 75 | public static void writeTotalTime(float secondstime){
|
| a62d533 | 76 | float curr = readTotalTime(); |
| a62d533 | 77 | prefs.putFloat(TOTAL_TIME, secondstime+curr); |
| a62d533 | 78 | prefs.flush(); |
| a62d533 | 79 | } |
| a62d533 | 80 | |
| a62d533 | 81 | static String addZero(int value){
|
| a62d533 | 82 | String str = ""; |
| a62d533 | 83 | if(value < 10) |
| a62d533 | 84 | str = "0" + value; |
| a62d533 | 85 | else |
| a62d533 | 86 | str = "" + value; |
| a62d533 | 87 | return str; |
| a62d533 | 88 | } |
| a62d533 | 89 | |
| a62d533 | 90 | public static int levels(){
|
| a62d533 | 91 | return prefs.getInteger(LEVELS, 20); |
| a62d533 | 92 | } |
| a62d533 | 93 | |
| a62d533 | 94 | public static void setLevels(int ue){
|
| a62d533 | 95 | prefs.putInteger(LEVELS, ue); |
| a62d533 | 96 | prefs.flush(); |
| a62d533 | 97 | } |
| a62d533 | 98 | |
| a62d533 | 99 | public static int currentLevel(){
|
| a62d533 | 100 | return prefs.getInteger(CURRENT_LEVEL, 0); |
| a62d533 | 101 | } |
| a62d533 | 102 | |
| a62d533 | 103 | public static void setCurrentLevel(int ue){
|
| a62d533 | 104 | prefs.putInteger(CURRENT_LEVEL, ue); |
| a62d533 | 105 | prefs.flush(); |
| a62d533 | 106 | } |
| a62d533 | 107 | |
| a62d533 | 108 | public static boolean isBattleEnabled(){
|
| a62d533 | 109 | return prefs.getBoolean(BATTLE_ANIMATION, true); |
| a62d533 | 110 | } |
| a62d533 | 111 | |
| a62d533 | 112 | public static void setBattle(boolean ue){
|
| a62d533 | 113 | prefs.putBoolean(BATTLE_ANIMATION, ue); |
| a62d533 | 114 | prefs.flush(); |
| a62d533 | 115 | } |
| a62d533 | 116 | |
| a62d533 | 117 | public static boolean isSemiAutomatic(){
|
| a62d533 | 118 | return prefs.getBoolean(SEMI_AUTOMATIC, false); |
| a62d533 | 119 | } |
| a62d533 | 120 | |
| a62d533 | 121 | public static void setSemiAutomatic(boolean ue){
|
| a62d533 | 122 | prefs.putBoolean(SEMI_AUTOMATIC, ue); |
| a62d533 | 123 | prefs.flush(); |
| a62d533 | 124 | } |
| a62d533 | 125 | |
| a62d533 | 126 | public static void setPanSpeed(float ue){
|
| a62d533 | 127 | prefs.putFloat(PANSPEED, ue); |
| a62d533 | 128 | prefs.flush(); |
| a62d533 | 129 | speedPan = ue; |
| a62d533 | 130 | } |
| a62d533 | 131 | |
| a62d533 | 132 | public static void setDragSpeed(float ue){
|
| a62d533 | 133 | prefs.putFloat(VOLUME_SOUND, ue); |
| a62d533 | 134 | prefs.flush(); |
| a62d533 | 135 | speedDrag = ue; |
| a62d533 | 136 | } |
| a62d533 | 137 | |
| a62d533 | 138 | public static void setKeyboard(boolean ue){
|
| a62d533 | 139 | prefs.putBoolean(KEYBOARD, ue); |
| a62d533 | 140 | prefs.flush(); |
| a62d533 | 141 | useKeyboard = ue; |
| a62d533 | 142 | } |
| a62d533 | 143 | |
| a62d533 | 144 | public static void setSound(boolean ue){
|
| a62d533 | 145 | prefs.putBoolean(SOUND, ue); |
| a62d533 | 146 | prefs.flush(); |
| a62d533 | 147 | isSound = ue ; |
| a62d533 | 148 | |
| a62d533 | 149 | } |
| a62d533 | 150 | |
| a62d533 | 151 | public static void setMusic(boolean ue){
|
| a62d533 | 152 | prefs.putBoolean(MUSIC, ue); |
| a62d533 | 153 | prefs.flush(); |
| a62d533 | 154 | isMusic = ue; |
| a62d533 | 155 | } |
| a62d533 | 156 | |
| a62d533 | 157 | public static void setMusicVolume(float ue){
|
| a62d533 | 158 | prefs.putFloat(VOLUME_MUSIC, ue); |
| a62d533 | 159 | prefs.flush(); |
| a62d533 | 160 | volMusic = ue; |
| a62d533 | 161 | Asset.musicVolume(); |
| a62d533 | 162 | } |
| a62d533 | 163 | |
| a62d533 | 164 | public static void setSoundVolume(float ue){
|
| a62d533 | 165 | prefs.putFloat(VOLUME_SOUND, ue); |
| a62d533 | 166 | prefs.flush(); |
| a62d533 | 167 | volSound = ue; |
| a62d533 | 168 | } |
| a62d533 | 169 | |
| a62d533 | 170 | public static void setScore(int value){
|
| a62d533 | 171 | prefs.putInteger(SCORE, value); |
| a62d533 | 172 | prefs.flush(); |
| a62d533 | 173 | score = value; |
| a62d533 | 174 | } |
| a62d533 | 175 | |
| a62d533 | 176 | public static int getScore(){
|
| a62d533 | 177 | return score; |
| a62d533 | 178 | } |
| a62d533 | 179 | |
| a62d533 | 180 | public static void setVibration(boolean ue){
|
| a62d533 | 181 | prefs.putBoolean(VIBRATION, ue); |
| a62d533 | 182 | prefs.flush(); |
| a62d533 | 183 | } |
| a62d533 | 184 | |
| a62d533 | 185 | public static boolean getVibration(){
|
| a62d533 | 186 | return prefs.getBoolean(VIBRATION, true); |
| a62d533 | 187 | } |
| a62d533 | 188 | |
| a62d533 | 189 | public static void setFirstLaunchDone(){
|
| a62d533 | 190 | prefs.putBoolean(FIRST_LAUNCH, false); |
| a62d533 | 191 | prefs.flush(); |
| a62d533 | 192 | |
| a62d533 | 193 | } |
| a62d533 | 194 | |
| a62d533 | 195 | public static boolean isFirstLaunch(){
|
| a62d533 | 196 | return prefs.getBoolean(FIRST_LAUNCH, true); |
| a62d533 | 197 | } |
| a62d533 | 198 | } |