Skip to content

Commit

Permalink
#valueOf() in Screens
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealEmissions committed Mar 19, 2024
1 parent ccf8f8c commit 6dadf08
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions core/src/uk/ac/york/student/screens/Screens.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package uk.ac.york.student.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import lombok.Getter;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Getter
@UtilityClass
/**
* A utility class to store the classes of the different screens loaded with reflection.
Expand Down Expand Up @@ -40,4 +35,18 @@ public final class Screens {
}
}
}

public static @Nullable Class<? extends BaseScreen> valueOf(String name) {
Field[] fields = Screens.class.getFields();
for (Field field : fields) {
if (field.getName().equals(name)) {
try {
return (Class<? extends BaseScreen>) field.get(null);
} catch (IllegalAccessException e) {
Gdx.app.error("Screens", "Could not access field " + name);
}
}
}
return null;
}
}

0 comments on commit 6dadf08

Please sign in to comment.