Package com.limelight.settings

Source Code of com.limelight.settings.GamepadSettingsManager

package com.limelight.settings;

import java.io.File;

import com.limelight.LimeLog;
import com.limelight.input.gamepad.GamepadMapping;

/**
* Manages the gamepad settings
* @author Diego Waxemberg
*/
public abstract class GamepadSettingsManager {
  private static GamepadMapping cachedSettings;

  /**
   * Reads the gamepad settings from the gamepad file and caches the configuration
   * @return the gamepad settings
   */
  public static GamepadMapping getSettings() {
    if (cachedSettings == null) {
      LimeLog.info("Reading Gamepad Settings");
      File gamepadFile = SettingsManager.getInstance().getGamepadFile();
      GamepadMapping savedMapping = (GamepadMapping)SettingsManager.readSettings(gamepadFile, GamepadMapping.class);
      cachedSettings = savedMapping;
    }
    if (cachedSettings == null) {
      LimeLog.warning("Unable to get gamepad settings. Using default mapping instead.");
      if (System.getProperty("os.name").contains("Windows")) {
        cachedSettings = GamepadMapping.getWindowsDefaultMapping();
      } else {
        cachedSettings = new GamepadMapping();
      }
      writeSettings(cachedSettings);
    }
    return cachedSettings;
  }

  /**
   * Writes the specified mapping to the gamepad file and updates the cached settings
   * @param settings the new gamepad mapping to be written out
   */
  public static void writeSettings(GamepadMapping settings) {
    cachedSettings = settings;
    LimeLog.info("Writing Gamepad Settings");
   
    File gamepadFile = SettingsManager.getInstance().getGamepadFile();
    SettingsManager.writeSettings(gamepadFile, settings);
  }

}
TOP

Related Classes of com.limelight.settings.GamepadSettingsManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.