{"size": 1702, "ext": "js", "max_stars_repo_path": "Flood/Assets/Scripts/ColorController.js", "max_stars_repo_name": "astennent/Flood", "max_stars_repo_stars_event_min_datetime": "2015-11-10T20:19:00.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-02T19:39:25.000Z", "max_issues_repo_path": "Flood/Assets/Scripts/ColorController.js", "max_issues_repo_name": "astennent/Flood", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Flood/Assets/Scripts/ColorController.js", "max_forks_repo_name": "astennent/Flood", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 34.04, "max_line_length": 98, "alphanum_fraction": 0.7121034078}
/* It is faster to store a list of pre-made materials and swap them out when needed than to create
   a new material every time a Tile is instantiated or flipped. So we store the list of all 
   usable colors as materials here, where the materials can be accessed quickly at runtime. */
public static var colorMaterials : List.<Material>;
public static var colors : Color[];
public var starColors : List.<Color>;

private static var THEME_KEY = "theme";
private static var s_instance : ColorController;

var board : Board;
var themes : ThemeButton[];

function Start() {
   s_instance = this;
   var savedThemeIndex = PlayerPrefs.GetInt(THEME_KEY);
   var defaultTheme = themes[savedThemeIndex];
   RefreshColorMaterials(defaultTheme.colors, defaultTheme.material);
   UpdateThemeButtonSelection();
}

static function RefreshColorMaterials(colors : Color[], material : Material) {
   colorMaterials = new List.<Material>();
   for (var i = 0 ; i < colors.length ; i++) {
      colorMaterials.Add(new Material(material));
      colorMaterials[i].SetColor("_Color", colors[i]);
   }
}

public function SetColors(themeButton : ThemeButton) {
   for (var i = 0 ; i < themes.length ; ++i) {
      if (themeButton == themes[i]) {
         PlayerPrefs.SetInt(THEME_KEY, i);
      } 
   }
   RefreshColorMaterials(themeButton.colors, themeButton.material);
   board.OnThemeChange();
   UpdateThemeButtonSelection();
}

private function UpdateThemeButtonSelection() {
   var theme_key = PlayerPrefs.GetInt(THEME_KEY);
   for (var i = 0 ; i < themes.length ; ++i) {
      themes[i].SetSelected(theme_key == i);
   }
}

static function GetStarColor(numColors : int) {
   return s_instance.starColors[numColors];
}