Added a getName function to convert enum names

This commit is contained in:
SomnusVeritas
2023-10-17 18:05:35 +02:00
parent 22d641e06f
commit e69aab7a04

View File

@@ -1,8 +1,12 @@
class DifficultyUtil { class DifficultyUtil {
static List<String> get difficulties { /// Converts lowerCamelCase or UpperCamelCase enum-names to 'normal' Strings
return List<String>.generate(Difficulty.values.length, static String getName(Difficulty difficulty) {
(index) => Difficulty.values.elementAt(index).name); String name = difficulty.name
.replaceAllMapped(RegExp(r'[A-Z]'), (match) => ' ${match[0]}');
name = name[0].toUpperCase() + name.substring(1);
return name;
} }
} }
// Only use camelCase or UpperCamelCase for names
enum Difficulty { veryEasy, easy, intermediate, hard, veryHard } enum Difficulty { veryEasy, easy, intermediate, hard, veryHard }