Search in sources :

Example 36 with Name

use of org.terasology.naming.Name in project Terasology by MovingBlocks.

the class BindsSubsystem method registerRealAxisBinds.

private void registerRealAxisBinds(ModuleEnvironment environment) {
    Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterRealBindAxis.class);
    for (Class<?> registerBindClass : classes) {
        RegisterRealBindAxis info = registerBindClass.getAnnotation(RegisterRealBindAxis.class);
        Name moduleId = environment.getModuleProviding(registerBindClass);
        SimpleUri id = new SimpleUri(moduleId, info.id());
        if (BindAxisEvent.class.isAssignableFrom(registerBindClass)) {
            try {
                BindAxisEvent instance = (BindAxisEvent) registerBindClass.newInstance();
                BindableAxis bindAxis = registerRealBindAxis(id.toString(), instance);
                bindAxis.setSendEventMode(info.eventMode());
                for (Input input : bindsConfiguration.getBinds(id)) {
                    linkAxisToInput(input, id);
                }
                logger.debug("Registered axis bind: {}", id);
            } catch (InstantiationException | IllegalAccessException e) {
                logger.error("Failed to register axis bind \"{}\"", id, e);
            }
        } else {
            logger.error("Failed to register axis bind \"{}\", does not extend BindAxisEvent", id);
        }
    }
}
Also used : RegisterRealBindAxis(org.terasology.input.RegisterRealBindAxis) ControllerInput(org.terasology.input.ControllerInput) Input(org.terasology.input.Input) MouseInput(org.terasology.input.MouseInput) SimpleUri(org.terasology.engine.SimpleUri) BindAxisEvent(org.terasology.input.BindAxisEvent) AbstractBindableAxis(org.terasology.input.internal.AbstractBindableAxis) BindableAxis(org.terasology.input.BindableAxis) Name(org.terasology.naming.Name)

Example 37 with Name

use of org.terasology.naming.Name in project Terasology by MovingBlocks.

the class StateHeadlessSetup method createGameManifest.

public GameManifest createGameManifest() {
    GameManifest gameManifest = new GameManifest();
    Config config = context.get(Config.class);
    ModuleManager moduleManager = context.get(ModuleManager.class);
    for (Name moduleName : config.getDefaultModSelection().listModules()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
        if (module != null) {
            gameManifest.addModule(module.getId(), module.getVersion());
        }
    }
    WorldGenerationConfig worldGenConfig = config.getWorldGeneration();
    // If no valid default world generator set then try to find one - no option to pick one manually in headless
    if (!worldGenConfig.getDefaultGenerator().isValid()) {
        // find the first gameplay module that is available, it should have a preferred world gen
        for (Name moduleName : config.getDefaultModSelection().listModules()) {
            Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
            if (StandardModuleExtension.isGameplayModule(module)) {
                SimpleUri defaultWorldGenerator = StandardModuleExtension.getDefaultWorldGenerator(module);
                worldGenConfig.setDefaultGenerator(defaultWorldGenerator);
                break;
            }
        }
    }
    SimpleUri worldGeneratorUri = worldGenConfig.getDefaultGenerator();
    gameManifest.setTitle(worldGenConfig.getWorldTitle());
    gameManifest.setSeed(worldGenConfig.getDefaultSeed());
    WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, gameManifest.getSeed(), (long) (WorldTime.DAY_LENGTH * 0.025f), worldGeneratorUri);
    gameManifest.addWorld(worldInfo);
    return gameManifest;
}
Also used : GameManifest(org.terasology.game.GameManifest) Config(org.terasology.config.Config) WorldGenerationConfig(org.terasology.config.WorldGenerationConfig) SimpleUri(org.terasology.engine.SimpleUri) WorldInfo(org.terasology.world.internal.WorldInfo) ModuleManager(org.terasology.engine.module.ModuleManager) Module(org.terasology.module.Module) WorldGenerationConfig(org.terasology.config.WorldGenerationConfig) Name(org.terasology.naming.Name)

Example 38 with Name

use of org.terasology.naming.Name in project Terasology by MovingBlocks.

the class ServerConnectionHandler method sendModules.

private void sendModules(List<NetData.ModuleRequest> moduleRequestList) {
    for (NetData.ModuleRequest request : moduleRequestList) {
        NetData.ModuleDataHeader.Builder result = NetData.ModuleDataHeader.newBuilder();
        result.setId(request.getModuleId());
        Module module = moduleManager.getEnvironment().get(new Name(request.getModuleId()));
        if (module.isOnClasspath() || module.getLocations().size() != 1 || !Files.isReadable(module.getLocations().get(0))) {
            result.setError("Module not available for download");
        } else {
            Path location = module.getLocations().get(0);
            try {
                result.setVersion(module.getVersion().toString());
                result.setSize(Files.size(location));
                channelHandlerContext.getChannel().write(NetData.NetMessage.newBuilder().setModuleDataHeader(result).build());
            } catch (IOException e) {
                logger.error("Error sending module data header", e);
                channelHandlerContext.getChannel().close();
                break;
            }
            try (InputStream stream = new BufferedInputStream(Files.newInputStream(location))) {
                long remainingData = Files.size(location);
                byte[] data = new byte[1024];
                while (remainingData > 0) {
                    int nextBlock = (int) Math.min(remainingData, 1024);
                    ByteStreams.read(stream, data, 0, nextBlock);
                    channelHandlerContext.getChannel().write(NetData.NetMessage.newBuilder().setModuleData(NetData.ModuleData.newBuilder().setModule(ByteString.copyFrom(data, 0, nextBlock))).build());
                    remainingData -= nextBlock;
                }
            } catch (IOException e) {
                logger.error("Error sending module", e);
                channelHandlerContext.getChannel().close();
                break;
            }
        }
    }
}
Also used : Path(java.nio.file.Path) NetData(org.terasology.protobuf.NetData) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Name(org.terasology.naming.Name) BufferedInputStream(java.io.BufferedInputStream) Module(org.terasology.module.Module)

Example 39 with Name

use of org.terasology.naming.Name in project Terasology by MovingBlocks.

the class ServerInfoMessageImpl method getModuleList.

@Override
public List<NameVersion> getModuleList() {
    List<NameVersion> result = Lists.newArrayList();
    for (NetData.ModuleInfo moduleInfo : info.getModuleList()) {
        if (!moduleInfo.hasModuleId() || !moduleInfo.hasModuleVersion()) {
            logger.error("Received incomplete module info");
        } else {
            Name id = new Name(moduleInfo.getModuleId());
            Version version = new Version(moduleInfo.getModuleVersion());
            result.add(new NameVersion(id, version));
        }
    }
    return result;
}
Also used : NameVersion(org.terasology.naming.NameVersion) NetData(org.terasology.protobuf.NetData) NameVersion(org.terasology.naming.NameVersion) Version(org.terasology.naming.Version) Name(org.terasology.naming.Name)

Example 40 with Name

use of org.terasology.naming.Name in project Terasology by MovingBlocks.

the class TranslationFormat method load.

@Override
public TranslationData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    if (inputs.size() != 1) {
        throw new IOException("Failed to load translation data '" + urn + "': " + inputs);
    }
    AssetDataFile file = inputs.get(0);
    Locale locale = localeFromFilename(file.getFilename());
    Name projName = basenameFromFilename(file.getFilename());
    SimpleUri projUri = new SimpleUri(urn.getModuleName(), projName);
    TranslationData data = new TranslationData(projUri, locale);
    try (InputStreamReader isr = new InputStreamReader(file.openStream(), Charsets.UTF_8)) {
        Map<String, String> entry = gson.fromJson(isr, MAP_TOKEN.getType());
        data.addAll(entry);
    } catch (JsonParseException e) {
        throw new IOException("Could not parse file '" + file + "'", e);
    }
    return data;
}
Also used : Locale(java.util.Locale) InputStreamReader(java.io.InputStreamReader) AssetDataFile(org.terasology.assets.format.AssetDataFile) SimpleUri(org.terasology.engine.SimpleUri) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) Name(org.terasology.naming.Name)

Aggregations

Name (org.terasology.naming.Name)43 Module (org.terasology.module.Module)14 ModuleManager (org.terasology.engine.module.ModuleManager)8 SimpleUri (org.terasology.engine.SimpleUri)7 DependencyResolver (org.terasology.module.DependencyResolver)7 ModuleEnvironment (org.terasology.module.ModuleEnvironment)7 ResourceUrn (org.terasology.assets.ResourceUrn)6 ResolutionResult (org.terasology.module.ResolutionResult)6 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)4 ModuleMetadata (org.terasology.module.ModuleMetadata)4 FromModule (org.terasology.module.predicates.FromModule)4 SubtextureData (org.terasology.rendering.assets.texture.subtexture.SubtextureData)4 Reader (java.io.Reader)3 Vector2f (org.terasology.math.geom.Vector2f)3 URL (java.net.URL)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 Test (org.junit.Test)2 Config (org.terasology.config.Config)2