mirror of
https://github.com/Anime-Game-Servers/AGSLunarCore.git
synced 2024-11-23 12:29:53 +00:00
Refactor resource loader
This commit is contained in:
parent
0d5ad9de04
commit
bb4342560a
@ -85,23 +85,6 @@ public class GameData {
|
||||
// Configs (Bin)
|
||||
@Getter private static Object2ObjectMap<String, FloorInfo> floorInfos = new Object2ObjectOpenHashMap<>();
|
||||
|
||||
public static Int2ObjectMap<?> getMapForExcel(Class<?> resourceDefinition) {
|
||||
Int2ObjectMap<?> map = null;
|
||||
|
||||
try {
|
||||
Field field = GameData.class.getDeclaredField(Utils.lowerCaseFirstChar(resourceDefinition.getSimpleName()) + "Map");
|
||||
field.setAccessible(true);
|
||||
|
||||
map = (Int2ObjectMap<?>) field.get(null);
|
||||
|
||||
field.setAccessible(false);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public static List<Integer> getAllRelicIds() {
|
||||
return relicExcelMap.values().stream().map(RelicExcel::getId).toList();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package emu.lunarcore.data;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -21,6 +22,7 @@ import emu.lunarcore.data.ResourceDeserializers.LunarCoreDoubleDeserializer;
|
||||
import emu.lunarcore.data.ResourceDeserializers.LunarCoreHashDeserializer;
|
||||
import emu.lunarcore.data.config.FloorInfo.FloorGroupSimpleInfo;
|
||||
import emu.lunarcore.data.custom.ActivityScheduleData;
|
||||
import emu.lunarcore.util.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
|
||||
public class ResourceLoader {
|
||||
@ -64,6 +66,23 @@ public class ResourceLoader {
|
||||
}
|
||||
}
|
||||
|
||||
private static Int2ObjectMap<?> getMapForExcel(Class<?> dataClass, Class<?> resourceDefinition) {
|
||||
Int2ObjectMap<?> map = null;
|
||||
|
||||
try {
|
||||
Field field = dataClass.getDeclaredField(Utils.lowerCaseFirstChar(resourceDefinition.getSimpleName()) + "Map");
|
||||
field.setAccessible(true);
|
||||
|
||||
map = (Int2ObjectMap<?>) field.get(null);
|
||||
|
||||
field.setAccessible(false);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private static List<Class<?>> getResourceDefClasses() {
|
||||
Reflections reflections = new Reflections(ResourceLoader.class.getPackage().getName());
|
||||
Set<?> classes = reflections.getSubTypesOf(GameResource.class);
|
||||
@ -90,7 +109,7 @@ public class ResourceLoader {
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
Int2ObjectMap map = GameData.getMapForExcel(resourceDefinition);
|
||||
Int2ObjectMap map = ResourceLoader.getMapForExcel(type.gameDataClass(), resourceDefinition);
|
||||
|
||||
try {
|
||||
loadFromResource(resourceDefinition, type, map);
|
||||
|
@ -9,6 +9,8 @@ public @interface ResourceType {
|
||||
/** Names of the file that this Resource loads from */
|
||||
String[] name();
|
||||
|
||||
Class<?> gameDataClass() default GameData.class;
|
||||
|
||||
/** Load priority - dictates which order to load this resource, with "highest" being loaded first */
|
||||
LoadPriority loadPriority() default LoadPriority.NORMAL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user