use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class EntitySerializerTest method setup.
@BeforeEach
public void setup() {
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
context.put(NetworkSystem.class, networkSystem);
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
entityManager = context.get(EngineEntityManager.class);
entityManager.getComponentLibrary().register(new ResourceUrn("test", "gettersetter"), GetterSetterComponent.class);
entityManager.getComponentLibrary().register(new ResourceUrn("test", "string"), StringComponent.class);
entityManager.getComponentLibrary().register(new ResourceUrn("test", "integer"), IntegerComponent.class);
entitySerializer = new EntitySerializer(entityManager);
componentLibrary = entityManager.getComponentLibrary();
PrefabData prefabData = new PrefabData();
prefabData.addComponent(new StringComponent("Value"));
prefab = Assets.generateAsset(new ResourceUrn("test:Test"), prefabData, Prefab.class);
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class StorageManagerTest method setup.
@BeforeEach
public void setup(@TempDir Path tempHome) throws Exception {
super.setup();
PathManager.getInstance().useOverrideHomePath(tempHome);
savePath = PathManager.getInstance().getSavePath("testSave");
assert !Files.isRegularFile(tempHome.resolve("global.dat"));
entityManager = context.get(EngineEntityManager.class);
moduleEnvironment = mock(ModuleEnvironment.class);
blockManager = context.get(BlockManager.class);
extraDataManager = context.get(ExtraBlockDataManager.class);
ModuleManager moduleManager = mock(ModuleManager.class);
when(moduleManager.getEnvironment()).thenReturn(moduleEnvironment);
RecordedEventStore recordedEventStore = new RecordedEventStore();
recordAndReplayUtils = new RecordAndReplayUtils();
CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, mock(TypeRegistry.class));
recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
context.put(StorageManager.class, esm);
this.character = entityManager.create();
Client client = createClientMock(PLAYER_ID, character);
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
when(networkSystem.getPlayers()).thenReturn(Arrays.asList(client));
context.put(NetworkSystem.class, networkSystem);
AssetManager assetManager = context.get(AssetManager.class);
BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
data.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
testBlock = context.get(BlockManager.class).getBlock("test:testblock");
testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");
context.put(ChunkProvider.class, mock(ChunkProvider.class));
WorldProvider worldProvider = mock(WorldProvider.class);
when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
context.put(WorldProvider.class, worldProvider);
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class TextureAssetResolverTest method testColorTextures.
@Test
public void testColorTextures() {
Random r = new FastRandom(123456);
for (int i = 0; i < 10; i++) {
int rgba = r.nextInt();
Color red = new Color(rgba);
ResourceUrn textureUriForColor = TextureUtil.getTextureUriForColor(red);
String simpleString = textureUriForColor.toString();
Optional<Texture> tex = Assets.getTexture(simpleString);
assertTrue(tex.isPresent());
ByteBuffer dataBuffer = tex.get().getData().getBuffers()[0];
int firstPixel = dataBuffer.asIntBuffer().get(0);
assertEquals(rgba, firstPixel);
}
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class TextureAssetResolverTest method testNoiseTextures.
@Test
public void testNoiseTextures() {
int size = 256;
ResourceUrn textureUriForWhiteNoise = TextureUtil.getTextureUriForWhiteNoise(size, 123354, 0, 255);
String simpleString = textureUriForWhiteNoise.toString();
Optional<Texture> tex = Assets.getTexture(simpleString);
assertTrue(tex.isPresent());
assertEquals(tex.get().getWidth(), size);
assertEquals(tex.get().getHeight(), size);
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class VectorEventSerializer method registerEvent.
// TODO: resolve hidden coupling in NetworkSystemImpl for fieldId's and EventSerializer
private void registerEvent(Class<? extends Event> clazz) {
entitySystemLibrary.getEventLibrary().register(new ResourceUrn("unittest", clazz.getName()), clazz);
EventMetadata<? extends Event> metadata = entitySystemLibrary.getEventLibrary().getMetadata(clazz);
byte fieldId = 0;
for (FieldMetadata<?, ?> field : metadata.getFields()) {
field.setId((byte) fieldId);
fieldId++;
}
eventMap.put(clazz, ++indexCount);
}
Aggregations