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();
}
});
}
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;
}
}
}
}
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.
}
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);
}
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;
}
Aggregations