use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.
the class BindsSubsystem method addButtonDefaultsFor.
private void addButtonDefaultsFor(Name moduleId, Iterable<Class<?>> classes, BindsConfiguration config) {
for (Class<?> buttonEvent : classes) {
if (ButtonEvent.class.isAssignableFrom(buttonEvent)) {
RegisterBindButton info = buttonEvent.getAnnotation(RegisterBindButton.class);
SimpleUri bindUri = new SimpleUri(moduleId, info.id());
if (!config.hasBinds(bindUri)) {
addDefaultBindings(bindUri, buttonEvent, config);
}
}
}
}
use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.
the class BindsSubsystem method registerButtonBinds.
private void registerButtonBinds(ModuleEnvironment environment) {
Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterBindButton.class);
for (Class<?> registerBindClass : classes) {
RegisterBindButton info = registerBindClass.getAnnotation(RegisterBindButton.class);
SimpleUri bindUri = new SimpleUri(environment.getModuleProviding(registerBindClass), info.id());
if (BindButtonEvent.class.isAssignableFrom(registerBindClass)) {
try {
BindableButton bindButton = registerBindButton(bindUri, info.description(), (BindButtonEvent) registerBindClass.newInstance());
bindButton.setMode(info.mode());
bindButton.setRepeating(info.repeating());
bindsConfiguration.getBinds(bindUri).stream().filter(input -> input != null).forEach(input -> linkBindButtonToInput(input, bindUri));
logger.debug("Registered button bind: {}", bindUri);
} catch (InstantiationException | IllegalAccessException e) {
logger.error("Failed to register button bind \"{}\"", e);
}
} else {
logger.error("Failed to register button bind \"{}\", does not extend BindButtonEvent", bindUri);
}
}
}
use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.
the class LocalPlayerSystem method startAutoMove.
/**
* Append the input for moving forward to the keyboard command queue to simulate pressing of the forward key. For an
* input that repeats, the key must be in Down state before Repeat state can be applied to it.
*/
private void startAutoMove() {
isAutoMove = false;
List<Input> inputs = bindsManager.getBindsConfig().getBinds(new SimpleUri("engine:forwards"));
Input forwardKey = getValidKey(inputs);
if (forwardKey != null) {
isAutoMove = true;
inputSystem.simulateSingleKeyStroke(forwardKey);
inputSystem.simulateRepeatedKeyStroke(forwardKey);
}
}
use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.
the class GameManifestProvider method createGameManifest.
/**
* Generates game manifest with default settings (title, seed) if not specified.
* Uses default world generator, and modules selection.
* @TODO: rewrite/fix it when code will be more stable
*
* @param universeWrapper contains the universe level properties
* @param moduleManager resolves modules
* @param config provides default module selection, world generator
* @return game manifest with default settings
*/
public static GameManifest createGameManifest(final UniverseWrapper universeWrapper, final ModuleManager moduleManager, final Config config) {
GameManifest gameManifest = new GameManifest();
if (StringUtils.isNotBlank(universeWrapper.getGameName())) {
gameManifest.setTitle(GameProvider.getNextGameName(universeWrapper.getGameName()));
} else {
gameManifest.setTitle(GameProvider.getNextGameName());
}
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
if (!result.isSuccess()) {
logger.error("Can't resolve dependencies");
return null;
}
for (Module module : result.getModules()) {
gameManifest.addModule(module.getId(), module.getVersion());
}
SimpleUri uri;
String seed;
WorldSetupWrapper worldSetup = universeWrapper.getTargetWorld();
if (worldSetup != null) {
uri = worldSetup.getWorldGenerator().getUri();
seed = worldSetup.getWorldGenerator().getWorldSeed();
} else {
uri = config.getWorldGeneration().getDefaultGenerator();
seed = universeWrapper.getSeed();
}
gameManifest.setSeed(seed);
String targetWorldName = "";
Map<String, Component> worldConfig = Maps.newHashMap();
if (worldSetup != null) {
targetWorldName = worldSetup.getWorldName().toString();
if (worldSetup.getWorldConfigurator() != null) {
// horrible hack to get configs into manifest.
// config driven by CreateWorldEntity.
// world config set somewhere else as well no clear drive from config --> world
gameManifest.setModuleConfigs(uri, worldSetup.getWorldConfigurator().getProperties());
}
}
// This is multiplied by the number of seconds in a day (86400000) to determine the exact millisecond at which the game will start.
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, targetWorldName, seed, (long) (WorldTime.DAY_LENGTH * WorldTime.SUNRISE_OFFSET), uri);
gameManifest.addWorld(worldInfo);
config.getUniverseConfig().addWorldManager(worldInfo);
config.getUniverseConfig().setSpawnWorldTitle(worldInfo.getTitle());
config.getUniverseConfig().setUniverseSeed(universeWrapper.getSeed());
return gameManifest;
}
use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.
the class BindsSubsystem method addAxisDefaultsFor.
private void addAxisDefaultsFor(Name moduleId, Iterable<Class<?>> classes, BindsConfiguration config) {
for (Class<?> axisEvent : classes) {
if (AxisEvent.class.isAssignableFrom(axisEvent)) {
RegisterRealBindAxis info = axisEvent.getAnnotation(RegisterRealBindAxis.class);
SimpleUri bindUri = new SimpleUri(moduleId, info.id());
if (!config.hasBinds(bindUri)) {
addDefaultBindings(bindUri, axisEvent, config);
}
}
}
}
Aggregations