Search in sources :

Example 11 with Name

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

the class EntitySystemSetupUtil method registerComponents.

static void registerComponents(ComponentLibrary library, ModuleEnvironment environment) {
    for (Class<? extends Component> componentType : environment.getSubtypesOf(Component.class)) {
        if (componentType.getAnnotation(DoNotAutoRegister.class) == null && !componentType.isInterface() && !Modifier.isAbstract(componentType.getModifiers())) {
            String componentName = MetadataUtil.getComponentClassName(componentType);
            Name componentModuleName = verifyNotNull(environment.getModuleProviding(componentType), "Could not find module for %s %s", componentName, componentType);
            library.register(new ResourceUrn(componentModuleName.toString(), componentName), componentType);
        }
    }
}
Also used : DoNotAutoRegister(org.terasology.engine.entitySystem.systems.internal.DoNotAutoRegister) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name)

Example 12 with Name

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

the class ComponentSystemManager method loadSystems.

public void loadSystems(ModuleEnvironment environment, NetworkMode netMode) {
    DisplayDevice display = context.get(DisplayDevice.class);
    boolean isHeadless = display.isHeadless();
    ListMultimap<Name, Class<?>> systemsByModule = ArrayListMultimap.create();
    for (Class<?> type : environment.getTypesAnnotatedWith(RegisterSystem.class)) {
        if (!ComponentSystem.class.isAssignableFrom(type)) {
            logger.error("Cannot load {}, must be a subclass of ComponentSystem", type.getSimpleName());
            continue;
        }
        Name moduleId = environment.getModuleProviding(type);
        RegisterSystem registerInfo = type.getAnnotation(RegisterSystem.class);
        if (registerInfo.value().isValidFor(netMode.isAuthority(), isHeadless) && areOptionalRequirementsContained(registerInfo, environment)) {
            systemsByModule.put(moduleId, type);
        }
    }
    for (Module module : environment.getModulesOrderedByDependencies()) {
        for (Class<?> system : systemsByModule.get(module.getId())) {
            String id = module.getId() + ":" + system.getSimpleName();
            logger.debug("Registering system {}", id);
            if (checkOptionalDependenciesPresent(system)) {
                tryToLoadSystem(system, id);
            } else {
                logger.warn("Skip system {} for loading - possibly missing optional dependencies", id);
            }
        }
    }
}
Also used : DisplayDevice(org.terasology.engine.core.subsystem.DisplayDevice) RegisterSystem(org.terasology.engine.entitySystem.systems.RegisterSystem) ComponentSystem(org.terasology.engine.entitySystem.systems.ComponentSystem) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Example 13 with Name

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

the class CoreCommands method spawnPrefab.

/**
 * Spawns an instance of a prefab in the world
 *
 * @param sender     Sender of command
 * @param prefabName String containing prefab name
 * @return String containing final message
 */
@Command(shortDescription = "Spawns an instance of a prefab in the world", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnPrefab(@Sender EntityRef sender, @CommandParam("prefabId") String prefabName) {
    ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
    LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
    Vector3f spawnPos = characterLocation.getWorldPosition(new Vector3f());
    Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
    offset.mul(2);
    spawnPos.add(offset);
    Vector3f dir = characterLocation.getWorldDirection(new Vector3f());
    dir.y = 0;
    if (dir.lengthSquared() > 0.001f) {
        dir.normalize();
    } else {
        dir.set(Direction.FORWARD.asVector3f());
    }
    return Assets.getPrefab(prefabName).map(prefab -> {
        LocationComponent loc = prefab.getComponent(LocationComponent.class);
        if (loc != null) {
            entityManager.create(prefab, spawnPos);
            return "Done";
        } else {
            return "Prefab cannot be spawned (no location component)";
        }
    }).orElse("Unknown prefab");
}
Also used : DropItemEvent(org.terasology.engine.logic.inventory.events.DropItemEvent) Server(org.terasology.engine.network.Server) Arrays(java.util.Arrays) Component(org.terasology.gestalt.entitysystem.component.Component) In(org.terasology.engine.registry.In) SystemConfig(org.terasology.engine.config.SystemConfig) Sender(org.terasology.engine.logic.console.commandSystem.annotations.Sender) Console(org.terasology.engine.logic.console.Console) SkinSuggester(org.terasology.engine.logic.console.suggesters.SkinSuggester) DisplayDevice(org.terasology.engine.core.subsystem.DisplayDevice) NUIEditorScreen(org.terasology.engine.rendering.nui.editor.layers.NUIEditorScreen) Locale(java.util.Locale) BlockUri(org.terasology.engine.world.block.BlockUri) FontColor(org.terasology.nui.FontColor) Vector3f(org.joml.Vector3f) TranslationProject(org.terasology.engine.i18n.TranslationProject) Path(java.nio.file.Path) StateLoading(org.terasology.engine.core.modes.StateLoading) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) CommandParam(org.terasology.engine.logic.console.commandSystem.annotations.CommandParam) ConsoleColors(org.terasology.engine.logic.console.ConsoleColors) GameEngine(org.terasology.engine.core.GameEngine) CommandNameSuggester(org.terasology.engine.logic.console.suggesters.CommandNameSuggester) WaitPopup(org.terasology.engine.rendering.nui.layers.mainMenu.WaitPopup) Set(java.util.Set) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) NUISkinEditorSystem(org.terasology.engine.rendering.nui.editor.systems.NUISkinEditorSystem) Streams(com.google.common.collect.Streams) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition) Instant(java.time.Instant) UISkinAsset(org.terasology.nui.skin.UISkinAsset) Collectors(java.util.stream.Collectors) Direction(org.terasology.engine.math.Direction) NUIManager(org.terasology.engine.rendering.nui.NUIManager) List(java.util.List) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) RegisterSystem(org.terasology.engine.entitySystem.systems.RegisterSystem) NUISkinEditorScreen(org.terasology.engine.rendering.nui.editor.layers.NUISkinEditorScreen) ScreenSuggester(org.terasology.engine.logic.console.suggesters.ScreenSuggester) Optional(java.util.Optional) Name(org.terasology.gestalt.naming.Name) TerasologyConstants(org.terasology.engine.core.TerasologyConstants) UIElement(org.terasology.nui.asset.UIElement) ModuleManager(org.terasology.engine.core.module.ModuleManager) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) NetworkMode(org.terasology.engine.network.NetworkMode) Callable(java.util.concurrent.Callable) BlockItemFactory(org.terasology.engine.world.block.items.BlockItemFactory) ArrayList(java.util.ArrayList) WorldDumper(org.terasology.engine.persistence.WorldDumper) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Time(org.terasology.engine.core.Time) StreamSupport(java.util.stream.StreamSupport) AssetManager(org.terasology.gestalt.assets.management.AssetManager) PingService(org.terasology.engine.network.PingService) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Assets(org.terasology.engine.utilities.Assets) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) PermissionManager(org.terasology.engine.logic.permission.PermissionManager) NUIEditorSystem(org.terasology.engine.rendering.nui.editor.systems.NUIEditorSystem) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ClientComponent(org.terasology.engine.network.ClientComponent) EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) PrefabManager(org.terasology.engine.entitySystem.prefab.PrefabManager) IOException(java.io.IOException) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) UnknownHostException(java.net.UnknownHostException) BaseComponentSystem(org.terasology.engine.entitySystem.systems.BaseComponentSystem) Ordering(com.google.common.collect.Ordering) BlockManager(org.terasology.engine.world.block.BlockManager) PrefabSerializer(org.terasology.engine.persistence.serializers.PrefabSerializer) JoinStatus(org.terasology.engine.network.JoinStatus) NetworkSystem(org.terasology.engine.network.NetworkSystem) PathManager(org.terasology.engine.core.PathManager) Vector3f(org.joml.Vector3f) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 14 with Name

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

the class CyclingTabCompletionEngine method complete.

@Override
public String complete(String rawCommand) {
    if (rawCommand.length() <= 0) {
        reset();
        previousMessage = new Message("Type 'help' to list all commands.");
        console.addMessage(previousMessage);
        return null;
    } else if (query == null) {
        query = rawCommand;
    }
    String commandNameRaw = console.processCommandName(query);
    Name commandName = new Name(commandNameRaw);
    List<String> commandParameters = console.processParameters(query);
    ConsoleCommand command = console.getCommand(commandName);
    int suggestedIndex = commandParameters.size() + (query.charAt(query.length() - 1) == ' ' ? 1 : 0);
    Set<String> matches = findMatches(commandName, commandParameters, command, suggestedIndex);
    if (matches == null || matches.size() <= 0) {
        return query;
    }
    if (previousMatches == null || !matches.equals(Sets.newHashSet(previousMatches))) {
        reset(false);
        if (matches.size() == 1) {
            return generateResult(matches.iterator().next(), commandName, commandParameters, suggestedIndex);
        }
        /*            if (matches.length > MAX_CYCLES) {
                console.addMessage(new Message("Too many hits, please refine your search"));
                return query;
            }*/
        // TODO Find out a better way to handle too many results while returning useful information
        previousMatches = Lists.newArrayList(matches);
        Collections.sort(previousMatches);
    }
    StringBuilder matchMessageString = new StringBuilder();
    for (int i = 0; i < previousMatches.size(); i++) {
        if (i > 0) {
            matchMessageString.append(' ');
        }
        String match = previousMatches.get(i);
        if (selectionIndex == i) {
            match = FontColor.getColored(match, ConsoleColors.COMMAND);
        }
        matchMessageString.append(match);
    }
    Message matchMessage = new Message(matchMessageString.toString());
    String suggestion = previousMatches.get(selectionIndex);
    if (previousMessage != null) {
        console.replaceMessage(previousMessage, matchMessage);
    } else {
        console.addMessage(matchMessage);
    }
    previousMessage = matchMessage;
    selectionIndex = (selectionIndex + 1) % previousMatches.size();
    return generateResult(suggestion, commandName, commandParameters, suggestedIndex);
}
Also used : Message(org.terasology.engine.logic.console.Message) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) Name(org.terasology.gestalt.naming.Name)

Example 15 with Name

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

the class ConsoleImpl method registerCommand.

/**
 * Registers a {@link ConsoleCommand}.
 *
 * @param command The command to be registered
 */
@Override
public void registerCommand(ConsoleCommand command) {
    Name commandName = command.getName();
    if (commandRegistry.containsKey(commandName)) {
        logger.warn("Command with name '{}' already registered by class '{}', skipping '{}'", commandName, commandRegistry.get(commandName).getSource().getClass().getCanonicalName(), command.getSource().getClass().getCanonicalName());
    } else {
        commandRegistry.put(commandName, command);
        logger.debug("Command '{}' successfully registered for class '{}'.", commandName, command.getSource().getClass().getCanonicalName());
    }
}
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