Search in sources :

Example 71 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class CoreCommands method editScreen.

/**
 * Opens the NUI editor for a ui screen
 *
 * @param uri String containing ui screen name
 * @return String containing final message
 */
@Command(shortDescription = "Opens the NUI editor for a ui screen", requiredPermission = PermissionManager.NO_PERMISSION)
public String editScreen(@CommandParam(value = "uri", suggester = ScreenSuggester.class) String uri) {
    if (!nuiEditorSystem.isEditorActive()) {
        nuiEditorSystem.toggleEditor();
    }
    Set<ResourceUrn> urns = assetManager.resolve(uri, UIElement.class);
    switch(urns.size()) {
        case 0:
            return String.format("No asset found for screen '%s'", uri);
        case 1:
            ResourceUrn urn = urns.iterator().next();
            ((NUIEditorScreen) nuiManager.getScreen(NUIEditorScreen.ASSET_URI)).selectAsset(urn);
            return "Success";
        default:
            return String.format("Multiple matches for screen '%s': {%s}", uri, Arrays.toString(urns.toArray()));
    }
}
Also used : ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) NUIEditorScreen(org.terasology.engine.rendering.nui.editor.layers.NUIEditorScreen) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 72 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class CoreCommands method findBlockMatches.

/**
 * List blocks that match searched string
 *
 * @param searchLowercase searched string
 * @return List of blocks that match searched string
 */
private List<String> findBlockMatches(String searchLowercase) {
    ResourceUrn curUrn;
    List<String> outputList = new ArrayList<>();
    for (ResourceUrn urn : assetManager.getAvailableAssets(BlockFamilyDefinition.class)) {
        // Current urn for logging purposes to find the broken urn
        curUrn = urn;
        try {
            Optional<BlockFamilyDefinition> def = assetManager.getAsset(urn, BlockFamilyDefinition.class);
            if (def.isPresent() && def.get().isLoadable() && matchesSearch(searchLowercase, def.get())) {
                outputList.add(new BlockUri(def.get().getUrn()).toString());
            }
        } catch (Exception e) {
            // If a prefab is broken , it will throw an exception
            console.addMessage("Note : Search may not return results if invalid assets are present");
            console.addMessage("Error parsing : " + curUrn.toString());
            console.addMessage(e.toString());
        }
    }
    return outputList;
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) ArrayList(java.util.ArrayList) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 73 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class CoreCommands method editSkin.

/**
 * Opens the NUI editor for a ui skin
 *
 * @param uri String containing name of ui skin
 * @return String containing final message
 */
@Command(shortDescription = "Opens the NUI editor for a ui skin", requiredPermission = PermissionManager.NO_PERMISSION)
public String editSkin(@CommandParam(value = "uri", suggester = SkinSuggester.class) String uri) {
    if (!nuiSkinEditorSystem.isEditorActive()) {
        nuiSkinEditorSystem.toggleEditor();
    }
    Set<ResourceUrn> urns = assetManager.resolve(uri, UISkinAsset.class);
    switch(urns.size()) {
        case 0:
            return String.format("No asset found for screen '%s'", uri);
        case 1:
            ResourceUrn urn = urns.iterator().next();
            ((NUISkinEditorScreen) nuiManager.getScreen(NUISkinEditorScreen.ASSET_URI)).selectAsset(urn);
            return "Success";
        default:
            return String.format("Multiple matches for screen '%s': {%s}", uri, Arrays.toString(urns.toArray()));
    }
}
Also used : NUISkinEditorScreen(org.terasology.engine.rendering.nui.editor.layers.NUISkinEditorScreen) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 74 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class AssetSuggester method suggest.

@Override
public Set<String> suggest(EntityRef sender, Object... resolvedParameters) {
    Map<String, Set<ResourceUrn>> resourceMap = Maps.newHashMap();
    Set<String> suggestions = Sets.newHashSet();
    for (ResourceUrn resolvedParameter : assetManager.getAvailableAssets(assetType)) {
        String resourceName = resolvedParameter.getResourceName().toString();
        if (!resourceMap.containsKey(resourceName)) {
            resourceMap.put(resourceName, Sets.newHashSet());
        }
        resourceMap.get(resourceName).add(resolvedParameter);
    }
    for (String key : resourceMap.keySet()) {
        Set<ResourceUrn> set = resourceMap.get(key);
        if (set.size() == 1) {
            suggestions.add(set.iterator().next().getResourceName().toString());
        } else {
            for (ResourceUrn resourceUrn : set) {
                suggestions.add(resourceUrn.toString());
            }
        }
    }
    return suggestions;
}
Also used : Set(java.util.Set) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 75 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class MovementDebugCommands method restoreSpeed.

@Command(shortDescription = "Restore normal speed values", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String restoreSpeed(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    Optional<Prefab> prefab = Assets.get(new ResourceUrn("engine:player"), Prefab.class);
    CharacterMovementComponent moveDefault = prefab.get().getComponent(CharacterMovementComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null && moveDefault != null) {
        move.jumpSpeed = moveDefault.jumpSpeed;
        move.speedMultiplier = moveDefault.speedMultiplier;
        move.runFactor = moveDefault.runFactor;
        move.stepHeight = moveDefault.stepHeight;
        move.slopeFactor = moveDefault.slopeFactor;
        move.distanceBetweenFootsteps = moveDefault.distanceBetweenFootsteps;
        clientComp.character.saveComponent(move);
    }
    return "Normal speed values restored";
}
Also used : CharacterMovementComponent(org.terasology.engine.logic.characters.CharacterMovementComponent) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ClientComponent(org.terasology.engine.network.ClientComponent) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Aggregations

ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)90 Test (org.junit.jupiter.api.Test)19 Name (org.terasology.gestalt.naming.Name)12 BeforeEach (org.junit.jupiter.api.BeforeEach)11 BlockFamilyDefinitionData (org.terasology.engine.world.block.loader.BlockFamilyDefinitionData)10 IOException (java.io.IOException)9 AssetManager (org.terasology.gestalt.assets.management.AssetManager)9 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)8 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)8 PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)7 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)7 BlockUri (org.terasology.engine.world.block.BlockUri)7 AssetDataFile (org.terasology.gestalt.assets.format.AssetDataFile)7 Texture (org.terasology.engine.rendering.assets.texture.Texture)5 BlockManagerImpl (org.terasology.engine.world.block.internal.BlockManagerImpl)5 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)5 NullWorldAtlas (org.terasology.engine.world.block.tiles.NullWorldAtlas)5 ExtraBlockDataManager (org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager)5 StringComponent (org.terasology.unittest.stubs.StringComponent)5 ByteBuffer (java.nio.ByteBuffer)4