PokeDex/lib/Session.dart

82 lines
1.7 KiB
Dart

import 'dart:math';
import 'package:pokedex/pokemon.dart';
class SessionData {
static bool enableDescription = true;
static bool darkMode = false;
static int highest = 9;
static int _cachedHighest = -1;
static final List<String> ALPHABET = [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"EM",
"QM",
];
static int _lastMaxID = 0;
static void resetHighestGenCache() {
_cachedHighest = -1;
}
static String getRandomUnownSprite() {
int index = Random().nextInt(ALPHABET.length);
var digit = ALPHABET[index];
return "assets/sprites/unown-${digit.toLowerCase()}.png";
}
static int highestGenID() {
if (_lastMaxID != Pokemon.values.length) resetHighestGenCache();
if (_cachedHighest != -1) return _cachedHighest;
List<Generation> gens = [];
if (highest >= 9) gens.add(Generation.Nine);
if (highest >= 8) gens.add(Generation.Eight);
if (highest >= 7) gens.add(Generation.Seven);
if (highest >= 6) gens.add(Generation.Six);
if (highest >= 5) gens.add(Generation.Five);
if (highest >= 4) gens.add(Generation.Four);
if (highest >= 3) gens.add(Generation.Three);
if (highest >= 2) gens.add(Generation.Two);
if (highest >= 1) gens.add(Generation.One);
int max = 0;
// Iterate over the list, and get the count of all pokemon from a specific generation
for (var gen in gens) {
for (var pokemon in Pokemon.values) {
if (pokemon.generation == gen) max++;
}
}
_cachedHighest = max;
_lastMaxID = Pokemon.values.length;
return max;
}
}