Search in sources :

Example 21 with Name

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

the class WorldSetupScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    WidgetUtil.trySubscribe(this, "close", button -> {
        final UniverseSetupScreen universeSetupScreen = getManager().createScreen(UniverseSetupScreen.ASSET_URI, UniverseSetupScreen.class);
        final WorldPreGenerationScreen worldPreGenerationScreen = getManager().createScreen(WorldPreGenerationScreen.ASSET_URI, WorldPreGenerationScreen.class);
        UIText customWorldName = find("customisedWorldName", UIText.class);
        boolean goBack = false;
        // sanity checks on world name
        if (customWorldName.getText().isEmpty()) {
            // name empty: display a popup, stay on the same screen
            getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Name Cannot Be Empty!", "Please add a name for the world");
        } else if (customWorldName.getText().equalsIgnoreCase(world.getWorldName().toString())) {
            // same name as before: go back to universe setup
            goBack = true;
        } else if (universeSetupScreen.worldNameMatchesAnother(customWorldName.getText())) {
            // if same name is already used, inform user with a  popup
            getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Name Already Used!", "Please use a different name for this world");
        } else {
            // no match found: go back to universe setup
            goBack = true;
        }
        if (goBack) {
            newWorldName = new Name(customWorldName.getText());
            world.setWorldName(newWorldName);
            universeSetupScreen.refreshWorldDropdown(worldsDropdown);
            worldPreGenerationScreen.setName(newWorldName);
            triggerBackAnimation();
        }
    });
}
Also used : UIText(org.terasology.nui.widgets.UIText) Name(org.terasology.gestalt.naming.Name)

Example 22 with Name

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

the class NewGameScreen method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    final UIText gameName = find("gameName", UIText.class);
    setGameName(gameName);
    final UIDropdown<Module> gameplay = find("gameplay", UIDropdown.class);
    String configDefaultModuleName = config.getDefaultModSelection().getDefaultGameplayModuleName();
    String useThisModuleName = "";
    // Otherwise, default to DEFAULT_GAME_TEMPLATE_NAME.
    if ("".equalsIgnoreCase(configDefaultModuleName) || DEFAULT_GAME_TEMPLATE_NAME.equalsIgnoreCase(configDefaultModuleName)) {
        useThisModuleName = DEFAULT_GAME_TEMPLATE_NAME;
    } else {
        useThisModuleName = configDefaultModuleName;
    }
    Name defaultGameplayModuleName = new Name(useThisModuleName);
    Module defaultGameplayModule = moduleManager.getRegistry().getLatestModuleVersion(defaultGameplayModuleName);
    if (defaultGameplayModule != null) {
        gameplay.setSelection(defaultGameplayModule);
        setDefaultGeneratorOfGameplayModule(defaultGameplayModule);
    } else {
        // Find the first gameplay module that is available.
        for (Module module : moduleManager.getRegistry()) {
            // Module is null if it is no longer present.
            if (module != null && StandardModuleExtension.isGameplayModule(module)) {
                gameplay.setSelection(module);
                break;
            }
        }
    }
}
Also used : UIText(org.terasology.nui.widgets.UIText) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Example 23 with Name

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

the class ClasspathCompromisingModuleFactoryTest method directoryModuleContainsClass.

@Test
public void directoryModuleContainsClass() {
    // This test assumes that the unittest module is under the current working directory (`engine-test/`)
    File engineTestDirectory = new File(System.getProperty("user.dir", "."));
    ModuleMetadata metadata = new ModuleMetadata(new Name("unittest"), new Version("1.0.0"));
    Module module = factory.createDirectoryModule(metadata, engineTestDirectory);
    // and that ExampleClass is inside that directory
    assertTrue(module.getClassPredicate().test(ExampleClass.class));
    // and that this other class (in engine, not engine-test) is outside that directory.
    assertFalse(module.getClassPredicate().test(someClassOutsideTheModule));
// These assumptions could break if things get moved around enough.
}
Also used : ExampleClass(org.terasology.unittest.ExampleClass) Version(org.terasology.gestalt.naming.Version) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) Module(org.terasology.gestalt.module.Module) File(java.io.File) Name(org.terasology.gestalt.naming.Name) Test(org.junit.jupiter.api.Test)

Example 24 with Name

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

the class BindsSubsystemTest method setUpMockModuleEnvironment.

private void setUpMockModuleEnvironment() {
    ModuleManager moduleManager = mock(ModuleManager.class);
    ModuleRegistry moduleRegistry = new TableModuleRegistry();
    Module module = mock(Module.class);
    when(module.getId()).thenReturn(new Name(TEST_MODULE));
    when(module.getVersion()).thenReturn(new Version(0, 0, 1, true));
    when(module.getMetadata()).thenReturn(new ModuleMetadata());
    moduleRegistry.add(module);
    when(moduleManager.getRegistry()).thenReturn(moduleRegistry);
    ModuleEnvironment environment = mock(ModuleEnvironment.class);
    when(moduleManager.loadEnvironment(any(), anyBoolean())).thenReturn(environment);
    when(moduleManager.getEnvironment()).thenReturn(environment);
    registerBindButtonClasses = new ArrayList<>();
    when(environment.getTypesAnnotatedWith(eq(RegisterBindButton.class))).thenReturn(registerBindButtonClasses);
    when(environment.getTypesAnnotatedWith(eq(RegisterBindButton.class), any())).thenReturn(registerBindButtonClasses);
    registerRealBindAxisClasses = new ArrayList<>();
    when(environment.getTypesAnnotatedWith(eq(RegisterBindAxis.class))).thenReturn(registerRealBindAxisClasses);
    when(environment.getTypesAnnotatedWith(eq(RegisterBindAxis.class), any())).thenReturn(registerRealBindAxisClasses);
    when(environment.getModuleProviding(any())).thenReturn(new Name(TEST_MODULE));
    context.put(ModuleManager.class, moduleManager);
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) Version(org.terasology.gestalt.naming.Version) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) RegisterBindAxis(org.terasology.engine.input.RegisterBindAxis) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Example 25 with Name

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

the class CommandNameSuggester method suggest.

@Override
public Set<Name> suggest(EntityRef sender, Object... resolvedParameters) {
    Collection<ConsoleCommand> commands = console.getCommands();
    Set<Name> suggestions = Sets.newHashSetWithExpectedSize(commands.size());
    for (ConsoleCommand command : commands) {
        suggestions.add(command.getName());
    }
    return suggestions;
}
Also used : ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) 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