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