Search in sources :

Example 61 with ResourceUrn

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

the class TextureUtilTest method testColorTransformedToAssetUriTransformedToColor.

@Test
public void testColorTransformedToAssetUriTransformedToColor() throws Exception {
    Color expectedColor = Color.RED;
    ResourceUrn assetUri = TextureUtil.getTextureUriForColor(expectedColor);
    Color actualColor = TextureUtil.getColorForColorName(assetUri.getFragmentName().toLowerCase());
    assertEquals(expectedColor, actualColor);
    int red = 0x12;
    int green = 0x3;
    int blue = 0xc4;
    int alpha = 0xe;
    expectedColor = new Color(red, green, blue, alpha);
    assetUri = TextureUtil.getTextureUriForColor(expectedColor);
    actualColor = TextureUtil.getColorForColorName(assetUri.getFragmentName().toLowerCase());
    assertEquals(expectedColor, actualColor);
}
Also used : Color(org.terasology.nui.Color) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Test(org.junit.jupiter.api.Test)

Example 62 with ResourceUrn

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

the class TextureUtilTest method testColorTransformedToTextureUri.

@Test
public void testColorTransformedToTextureUri() throws Exception {
    ResourceUrn assetUri = TextureUtil.getTextureUriForColor(Color.RED);
    assertEquals(TerasologyConstants.ENGINE_MODULE, assetUri.getModuleName());
    assertEquals(new Name("color"), assetUri.getResourceName());
    assertEquals(new Name("ff0000ff"), assetUri.getFragmentName());
    int red = 0x12;
    int green = 0x3;
    int blue = 0xc4;
    int alpha = 0xe;
    assetUri = TextureUtil.getTextureUriForColor(new Color(red, green, blue, alpha));
    assertEquals(TerasologyConstants.ENGINE_MODULE, assetUri.getModuleName());
    assertEquals(new Name("color"), assetUri.getResourceName());
    assertEquals(new Name("1203c40e"), assetUri.getFragmentName());
}
Also used : Color(org.terasology.nui.Color) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name) Test(org.junit.jupiter.api.Test)

Example 63 with ResourceUrn

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

the class EnvironmentSwitchHandler method registerComponents.

private 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 64 with ResourceUrn

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

the class StateIngame method dispose.

@Override
public void dispose(boolean shuttingDown) {
    ChunkProvider chunkProvider = context.get(ChunkProvider.class);
    chunkProvider.dispose();
    AssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class);
    // dispose all module assets
    assetTypeManager.getAssetTypes().forEach(assetType -> {
        for (ResourceUrn urn : assetType.getLoadedAssetUrns()) {
            if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) {
                assetType.getAsset(urn).ifPresent(Asset::dispose);
            }
        }
    });
    // dispose engine assets that should not be kept when switching game states
    assetTypeManager.getAssetType(BlockFamilyDefinition.class).ifPresent(AssetType::disposeAll);
    assetTypeManager.getAssetType(Prefab.class).ifPresent(AssetType::disposeAll);
    boolean save = networkSystem.getMode().isAuthority();
    if (save && storageManager != null) {
        storageManager.waitForCompletionOfPreviousSaveAndStartSaving();
    }
    networkSystem.shutdown();
    // TODO: Shutdown background threads
    eventSystem.process();
    GameThread.processWaitingProcesses();
    if (nuiManager != null) {
        nuiManager.clear();
    }
    context.get(AudioManager.class).stopAllSounds();
    if (worldRenderer != null) {
        worldRenderer.dispose();
        worldRenderer = null;
    }
    componentSystemManager.shutdown();
    context.get(PhysicsEngine.class).dispose();
    entityManager.clear();
    if (storageManager != null) {
        storageManager.finishSavingAndShutdown();
    }
    ModuleEnvironment oldEnvironment = context.get(ModuleManager.class).getEnvironment();
    context.get(ModuleManager.class).loadEnvironment(Collections.<Module>emptySet(), true);
    if (!shuttingDown) {
        context.get(EnvironmentSwitchHandler.class).handleSwitchToEmptyEnvironment(context);
    }
    if (oldEnvironment != null) {
        oldEnvironment.close();
    }
    console.dispose();
    GameThread.clearWaitingProcesses();
    if (nuiManager != null) {
        /*
             * Clear the binding as otherwise the complete ingame state would be
             * referenced.
             */
        nuiManager.getHUD().clearVisibleBinding();
    }
}
Also used : PhysicsEngine(org.terasology.engine.physics.engine.PhysicsEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) AudioManager(org.terasology.engine.audio.AudioManager) AssetType(org.terasology.gestalt.assets.AssetType) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) AssetTypeManager(org.terasology.gestalt.assets.management.AssetTypeManager) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Asset(org.terasology.gestalt.assets.Asset) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 65 with ResourceUrn

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

the class ColorConstraintWidgetFactory method bindWidgetToSetting.

@Override
protected void bindWidgetToSetting(UIWidget widget) {
    UIImage img = widget.find("image", UIImage.class);
    if (img != null) {
        ResourceUrn uri = TextureUtil.getTextureUriForColor(Color.WHITE);
        Texture tex = assetManager.getAsset(uri, Texture.class).get();
        img.setImage(tex);
        img.bindTint(new SettingBinding<>(getSetting()));
    }
    UISlider slider = widget.find("tone", UISlider.class);
    slider.setIncrement(0.01f);
    // ensure a certain width
    Function<Object, String> constant = Functions.constant("  ");
    slider.setLabelFunction(constant);
    slider.bindValue(new MappingBinding<>(new SettingBinding<>(getSetting()), this::findClosestColor, this::findClosestIndex));
}
Also used : UISlider(org.terasology.nui.widgets.UISlider) SettingBinding(org.terasology.engine.config.flexible.bindings.SettingBinding) UIImage(org.terasology.nui.widgets.UIImage) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Texture(org.terasology.engine.rendering.assets.texture.Texture)

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