use of org.terasology.engine.core.module.ModuleManager in project Terasology by MovingBlocks.
the class HeadlessEnvironment method setupStorageManager.
@Override
protected void setupStorageManager() throws IOException {
ModuleManager moduleManager = context.get(ModuleManager.class);
EngineEntityManager engineEntityManager = context.get(EngineEntityManager.class);
BlockManager blockManager = context.get(BlockManager.class);
RecordAndReplaySerializer recordAndReplaySerializer = context.get(RecordAndReplaySerializer.class);
Path savePath = PathManager.getInstance().getSavePath("world1");
RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils();
RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
context.put(BlockFamilyLibrary.class, new BlockFamilyLibrary(environment, context));
ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
context.put(StorageManager.class, new ReadWriteStorageManager(savePath, moduleManager.getEnvironment(), engineEntityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus));
}
use of org.terasology.engine.core.module.ModuleManager in project Terasology by MovingBlocks.
the class ModuleManagerFactory method create.
public static ModuleManager create() throws Exception {
// Loading screens, among other things, break when NUI classes are not added to engine.
ModuleManager moduleManager = new ModuleManager("", ImmutableList.of(UIWidget.class));
Module unittestModule = moduleManager.registerPackageModule("org.terasology.unittest");
moduleManager.resolveAndLoadEnvironment(unittestModule.getId());
return moduleManager;
}
use of org.terasology.engine.core.module.ModuleManager in project Terasology by MovingBlocks.
the class WithUnittestModule method initialise.
@Override
public void initialise(GameEngine engine, Context rootContext) {
EngineSubsystem.super.initialise(engine, rootContext);
ModuleManager manager = rootContext.get(ModuleManager.class);
Module unittestModule = manager.registerPackageModule("org.terasology.unittest");
manager.resolveAndLoadEnvironment(unittestModule.getId());
}
use of org.terasology.engine.core.module.ModuleManager in project Terasology by MovingBlocks.
the class BindingScraper method main.
/**
* @param args (ignored)
* @throws Exception if the module environment cannot be loaded
*/
public static void main(String[] args) throws Exception {
ModuleManager moduleManager = ModuleManagerFactory.create();
// Holds normal input mappings where there is only one key
Multimap<InputCategory, String> categories = ArrayListMultimap.create();
Multimap<String, Input> keys = ArrayListMultimap.create();
Map<String, String> desc = new HashMap<>();
for (Class<?> holdingType : moduleManager.getEnvironment().getTypesAnnotatedWith(InputCategory.class)) {
InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
categories.put(inputCategory, null);
for (String button : inputCategory.ordering()) {
categories.put(inputCategory, button);
}
}
for (Class<?> buttonEvent : moduleManager.getEnvironment().getTypesAnnotatedWith(RegisterBindButton.class)) {
DefaultBinding defBinding = buttonEvent.getAnnotation(DefaultBinding.class);
RegisterBindButton info = buttonEvent.getAnnotation(RegisterBindButton.class);
String cat = info.category();
String id = "engine:" + info.id();
desc.put(id, info.description());
if (cat.isEmpty()) {
InputCategory inputCategory = findEntry(categories, id);
if (inputCategory == null) {
System.out.println("Invalid category for: " + info.id());
}
} else {
InputCategory inputCategory = findCategory(categories, cat);
if (inputCategory != null) {
categories.put(inputCategory, id);
} else {
System.out.println("Invalid category for: " + info.id());
}
}
if (defBinding != null) {
// This handles bindings with just one key
Input input = defBinding.type().getInput(defBinding.id());
keys.put(id, input);
} else {
// See if there is a multi-mapping for this button
DefaultBindings multiBinding = buttonEvent.getAnnotation(DefaultBindings.class);
// Annotation math magic. We're expecting a DefaultBindings containing one DefaultBinding pair
if (multiBinding != null && multiBinding.value().length == 2) {
DefaultBinding[] bindings = multiBinding.value();
Input primary = bindings[0].type().getInput(bindings[0].id());
Input secondary = bindings[1].type().getInput(bindings[1].id());
keys.put(id, primary);
keys.put(id, secondary);
}
}
}
for (InputCategory row : categories.keySet()) {
System.out.println("# " + row.displayName());
categories.get(row).stream().filter(entry -> entry != null).forEach(entry -> System.out.println(desc.get(entry) + ": " + keys.get(entry)));
}
}
use of org.terasology.engine.core.module.ModuleManager in project Terasology by MovingBlocks.
the class CompleteApiScraper method getApi.
/**
* @return Project's Packages, Interfaces, Classes and Methods
* @throws Exception if the module environment cannot be loaded
*/
static StringBuffer getApi() throws Exception {
ModuleManager moduleManager = ModuleManagerFactory.create();
ModuleEnvironment environment = moduleManager.getEnvironment();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Multimap<String, String> api = Multimaps.newMultimap(new HashMap<String, Collection<String>>(), ArrayList::new);
for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) {
boolean isPackage = apiClass.isSynthetic();
URL location;
String category;
String apiPackage = "";
if (isPackage) {
apiPackage = apiClass.getPackage().getName();
location = classLoader.getResource(apiPackage.replace('.', '/'));
} else {
location = apiClass.getResource('/' + apiClass.getName().replace('.', '/') + ".class");
}
if (location == null) {
logger.error("Failed to get a class/package location, skipping " + apiClass);
continue;
}
switch(location.getProtocol()) {
case "jar":
// Find out what jar it came from and consider that the category
String categoryFragment = location.getPath();
int bang = categoryFragment.lastIndexOf("!");
int hyphen = categoryFragment.lastIndexOf("-", bang);
int slash = categoryFragment.lastIndexOf("/", hyphen);
category = categoryFragment.substring(slash + 1, hyphen);
if (isPackage) {
api.put(category, apiPackage + " (PACKAGE)");
} else {
addToApi(category, apiClass, api);
}
break;
case "file":
// If file based we know it is local so organize it like that
category = TERASOLOGY_API_CLASS_CATEGORY;
if (isPackage) {
api.put(category, apiPackage + " (PACKAGE)");
} else {
addToApi(category, apiClass, api);
}
break;
default:
logger.error("Unknown protocol for: " + apiClass + ", came from " + location);
}
}
api.putAll(EXTERNAL, ExternalApiWhitelist.CLASSES.stream().map(clazz -> clazz.getName() + " (CLASS)").collect(Collectors.toSet()));
api.putAll(EXTERNAL, ExternalApiWhitelist.PACKAGES.stream().map(packagee -> packagee + " (PACKAGE)").collect(Collectors.toSet()));
// Puts the information in the StringBuffer
StringBuffer stringApi = new StringBuffer();
stringApi.append("# Modding API:\n");
for (String key : api.keySet()) {
stringApi.append("## ");
stringApi.append(key);
stringApi.append("\n");
for (String value : api.get(key)) {
stringApi.append("* ");
stringApi.append(value);
stringApi.append("\n");
}
stringApi.append("\n");
}
return stringApi;
}
Aggregations