Search in sources :

Example 16 with Name

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

the class AtlasFormat method process.

private void process(GridDefinition grid, Texture texture, Vector2ic size, Map<Name, SubtextureData> out) {
    if (grid.getTileSize() == null) {
        logger.error("Bad grid definition - missing mandatory property tileSize");
        return;
    }
    if (grid.getGridDimensions() == null) {
        logger.error("Bad grid definition - missing mandatory property gridDimensions");
        return;
    }
    Vector2f offset = new Vector2f(0, 0);
    if (grid.getGridOffset() != null) {
        offset.set((float) grid.getGridOffset().x / size.x(), (float) grid.getGridOffset().y / size.y());
    }
    Vector2f tileSize = new Vector2f((float) grid.getTileSize().x / size.x(), (float) grid.getTileSize().y / size.y());
    int tileX = 0;
    int tileY = 0;
    for (String name : grid.getTileNames()) {
        if (!name.isEmpty()) {
            Vector2f pos = new Vector2f(offset);
            pos.x += tileX * tileSize.x;
            pos.y += tileY * tileSize.y;
            Rectanglef tileLocation = new Rectanglef(offset.x + tileX * tileSize.x, offset.y + tileY * tileSize.y, 0.0f, 0.0f).setSize(tileSize.x, tileSize.y);
            out.put(new Name(name), new SubtextureData(texture, shrinkRegion(tileLocation)));
        }
        tileX++;
        if (tileX == grid.getGridDimensions().x) {
            tileX = 0;
            tileY++;
        }
    }
}
Also used : Vector2f(org.joml.Vector2f) Rectanglef(org.terasology.joml.geom.Rectanglef) SubtextureData(org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData) Name(org.terasology.gestalt.naming.Name)

Example 17 with Name

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

the class AtlasFormat method load.

@Override
public AtlasData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    try (Reader reader = new InputStreamReader(inputs.get(0).openStream(), Charsets.UTF_8)) {
        AtlasDefinition def = gson.fromJson(reader, AtlasDefinition.class);
        Optional<? extends Texture> texture = assetManager.getAsset(def.getTexture(), Texture.class);
        if (texture.isPresent()) {
            Vector2i size = def.getTextureSize();
            if (size == null) {
                size = new Vector2i(texture.get().getWidth(), texture.get().getHeight());
            }
            Map<Name, SubtextureData> result = Maps.newHashMap();
            if (def.getGrid() != null) {
                process(def.getGrid(), texture.get(), size, result);
            }
            if (def.getGrids() != null) {
                for (GridDefinition grid : def.getGrids()) {
                    process(grid, texture.get(), size, result);
                }
            }
            if (def.getSubimage() != null) {
                process(def.getSubimage(), texture.get(), size, result);
            }
            if (def.getSubimages() != null) {
                for (FreeformDefinition freeform : def.getSubimages()) {
                    process(freeform, texture.get(), size, result);
                }
            }
            return new AtlasData(result);
        }
        return null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) SubtextureData(org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Vector2i(org.joml.Vector2i) Name(org.terasology.gestalt.naming.Name)

Example 18 with Name

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

the class AdvancedGameSetupScreen method updateModuleInformation.

private void updateModuleInformation() {
    Iterable<Module> remoteModuleRegistry = moduleManager.getInstallManager().getRemoteRegistry();
    Set<Name> filtered = ImmutableSet.of(TerasologyConstants.ENGINE_MODULE, new Name("engine-test"));
    for (Module remote : remoteModuleRegistry) {
        ModuleSelectionInfo info = modulesLookup.get(remote.getId());
        if (!filtered.contains(remote.getId())) {
            if (info == null) {
                info = ModuleSelectionInfo.remote(remote);
                modulesLookup.put(remote.getId(), info);
            }
            info.setOnlineVersion(remote);
        }
    }
    sortedModules.clear();
    allSortedModules.clear();
    sortedModules.addAll(modulesLookup.values());
    sortedModules.sort(moduleInfoComparator);
    allSortedModules.addAll(sortedModules);
    filterModules();
    refreshSelection();
}
Also used : Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Example 19 with Name

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

the class InputSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    ColumnLayout mainLayout = find("main", ColumnLayout.class);
    UIButton azerty = find("azerty", UIButton.class);
    if (azerty != null) {
        azerty.subscribe(event -> {
            BindCommands.AZERTY.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UIButton dvorak = find("dvorak", UIButton.class);
    if (dvorak != null) {
        dvorak.subscribe(event -> {
            BindCommands.DVORAK.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UIButton neo = find("neo", UIButton.class);
    if (neo != null) {
        neo.subscribe(event -> {
            BindCommands.NEO.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UISlider mouseSensitivity = new UISlider("mouseSensitivity");
    mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
    mouseSensitivity.setIncrement(0.025f);
    mouseSensitivity.setPrecision(3);
    UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
    mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
    if (mainLayout != null) {
        mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu" + "#category-mouse}")));
        mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse" + "-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
        mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    }
    Map<String, InputCategory> inputCategories = Maps.newHashMap();
    Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        ResolutionResult result = resolver.resolve(moduleId);
        if (result.isSuccess()) {
            try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
                    InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
                    inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
                }
                for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
                    if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
                        RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
                        inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
                    }
                }
            }
        }
    }
    if (mainLayout != null) {
        addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
        for (InputCategory category : inputCategories.values()) {
            addInputSection(category, mainLayout, inputsById);
        }
        mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
        List<String> controllers = inputSystem.getControllerDevice().getControllers();
        for (String name : controllers) {
            ControllerInfo cfg = inputDeviceConfiguration.getController(name);
            addInputSection(mainLayout, name, cfg);
        }
    }
    WidgetUtil.trySubscribe(this, "reset", button -> {
        inputDeviceConfiguration.reset();
        bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
    });
    WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) UISlider(org.terasology.nui.widgets.UISlider) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) UICheckbox(org.terasology.nui.widgets.UICheckbox) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Name(org.terasology.gestalt.naming.Name) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ColumnLayout(org.terasology.nui.layouts.ColumnLayout) UIButton(org.terasology.nui.widgets.UIButton) RowLayout(org.terasology.nui.layouts.RowLayout) InputCategory(org.terasology.input.InputCategory) UISpace(org.terasology.nui.widgets.UISpace) Vector2i(org.joml.Vector2i) FromModule(org.terasology.gestalt.module.predicates.FromModule) Module(org.terasology.gestalt.module.Module) FromModule(org.terasology.gestalt.module.predicates.FromModule) ControllerInfo(org.terasology.engine.config.ControllerConfig.ControllerInfo)

Example 20 with Name

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

the class UniverseSetupScreen method getAllEnabledModuleNames.

private Set<Name> getAllEnabledModuleNames() {
    final Set<Name> enabledModules = Sets.newHashSet();
    for (Name moduleName : config.getDefaultModSelection().listModules()) {
        enabledModules.add(moduleName);
        recursivelyAddModuleDependencies(enabledModules, moduleName);
    }
    return enabledModules;
}
Also used : Name(org.terasology.gestalt.naming.Name)

Aggregations

Name (org.terasology.gestalt.naming.Name)58 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)15 Module (org.terasology.gestalt.module.Module)14 SimpleUri (org.terasology.engine.core.SimpleUri)13 ModuleManager (org.terasology.engine.core.module.ModuleManager)10 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)7 IOException (java.io.IOException)6 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)6 List (java.util.List)5 GameEngine (org.terasology.engine.core.GameEngine)5 SubtextureData (org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData)5 BlockUri (org.terasology.engine.world.block.BlockUri)5 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)5 UIText (org.terasology.nui.widgets.UIText)5 Map (java.util.Map)4 Set (java.util.Set)4 Config (org.terasology.engine.config.Config)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3