예제 #1
0
  @Override
  protected void setupAssetManager() {
    setupEmptyAssetManager();

    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    AudioManager audioManager = CoreRegistry.get(AudioManager.class);
    AssetType.registerAssetTypes(assetManager);

    CodeSource tsCodeSource = TerasologyEngine.class.getProtectionDomain().getCodeSource();
    assetManager.addAssetSource(
        new ClasspathSource(
            TerasologyConstants.ENGINE_MODULE,
            tsCodeSource,
            TerasologyConstants.ASSETS_SUBDIRECTORY,
            TerasologyConstants.OVERRIDES_SUBDIRECTORY));

    CodeSource thisCodeSource = HeadlessEnvironment.class.getProtectionDomain().getCodeSource();
    assetManager.addAssetSource(
        new ClasspathSource(
            "unittest",
            thisCodeSource,
            TerasologyConstants.ASSETS_SUBDIRECTORY,
            TerasologyConstants.OVERRIDES_SUBDIRECTORY));

    assetManager.setAssetFactory(
        AssetType.PREFAB,
        new AssetFactory<PrefabData, Prefab>() {

          @Override
          public Prefab buildAsset(AssetUri uri, PrefabData data) {
            return new PojoPrefab(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.SHAPE,
        new AssetFactory<BlockShapeData, BlockShape>() {

          @Override
          public BlockShape buildAsset(AssetUri uri, BlockShapeData data) {
            return new BlockShapeImpl(uri, data);
          }
        });

    assetManager.setAssetFactory(
        AssetType.UI_SKIN,
        new AssetFactory<UISkinData, UISkin>() {
          @Override
          public UISkin buildAsset(AssetUri uri, UISkinData data) {
            return new UISkin(uri, data);
          }
        });

    assetManager.setAssetFactory(AssetType.SOUND, audioManager.getStaticSoundFactory());
    assetManager.setAssetFactory(AssetType.MUSIC, audioManager.getStreamingSoundFactory());
  }
예제 #2
0
  private void initAssets() {
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    assetManager.setAssetFactory(
        AssetType.PREFAB,
        new AssetFactory<PrefabData, Prefab>() {

          @Override
          public Prefab buildAsset(AssetUri uri, PrefabData data) {
            return new PojoPrefab(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.SHAPE,
        new AssetFactory<BlockShapeData, BlockShape>() {

          @Override
          public BlockShape buildAsset(AssetUri uri, BlockShapeData data) {
            return new BlockShapeImpl(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.UI_SKIN,
        new AssetFactory<UISkinData, UISkin>() {
          @Override
          public UISkin buildAsset(AssetUri uri, UISkinData data) {
            return new UISkin(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.BEHAVIOR,
        new AssetFactory<BehaviorTreeData, BehaviorTree>() {
          @Override
          public BehaviorTree buildAsset(AssetUri uri, BehaviorTreeData data) {
            return new BehaviorTree(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.UI_ELEMENT,
        new AssetFactory<UIData, UIElement>() {
          @Override
          public UIElement buildAsset(AssetUri uri, UIData data) {
            return new UIElement(uri, data);
          }
        });
  }
예제 #3
0
  @Override
  protected void setupEmptyAssetManager() {
    ModuleManager moduleManager = CoreRegistry.get(ModuleManager.class);
    AssetManager assetManager = new AssetManager(moduleManager);

    // mock an empy asset factory for all asset types
    for (AssetType type : AssetType.values()) {
      assetManager.setAssetFactory(type, mock(AssetFactory.class));
    }

    CoreRegistry.put(AssetManager.class, assetManager);
  }
  @Before
  public void setup() {
    GameThread.setGameThread();
    AssetManager assetManager =
        CoreRegistry.put(
            AssetManager.class,
            new AssetManager(new ModuleManagerImpl(new ModuleSecurityManager())));
    assetManager.setAssetFactory(
        AssetType.PREFAB,
        new AssetFactory<PrefabData, Prefab>() {

          @Override
          public Prefab buildAsset(AssetUri uri, PrefabData data) {
            return new PojoPrefab(uri, data);
          }
        });
    EntitySystemBuilder builder = new EntitySystemBuilder();

    CoreRegistry.put(ComponentSystemManager.class, mock(ComponentSystemManager.class));

    blockManager =
        CoreRegistry.put(
            BlockManager.class,
            new BlockManagerImpl(mock(WorldAtlas.class), new DefaultBlockFamilyFactoryRegistry()));
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    entityManager = builder.build(moduleManager, networkSystem, new ReflectionReflectFactory());
    worldStub = new WorldProviderCoreStub(BlockManager.getAir());
    worldProvider = new EntityAwareWorldProvider(worldStub, entityManager);

    plainBlock = new Block();
    blockManager.addBlockFamily(
        new SymmetricFamily(new BlockUri("test:plainBlock"), plainBlock), true);

    blockWithString = new Block();
    PrefabData prefabData = new PrefabData();
    prefabData.addComponent(new StringComponent("Test"));
    Assets.generateAsset(
        new AssetUri(AssetType.PREFAB, "test:prefabWithString"), prefabData, Prefab.class);
    blockWithString.setPrefab("test:prefabWithString");
    blockManager.addBlockFamily(
        new SymmetricFamily(new BlockUri("test:blockWithString"), blockWithString), true);

    blockWithDifferentString = new Block();
    prefabData = new PrefabData();
    prefabData.addComponent(new StringComponent("Test2"));
    Assets.generateAsset(
        new AssetUri(AssetType.PREFAB, "test:prefabWithDifferentString"), prefabData, Prefab.class);
    blockWithDifferentString.setPrefab("test:prefabWithDifferentString");
    blockManager.addBlockFamily(
        new SymmetricFamily(
            new BlockUri("test:blockWithDifferentString"), blockWithDifferentString),
        true);

    blockWithRetainedComponent = new Block();
    prefabData = new PrefabData();
    prefabData.addComponent(new RetainedOnBlockChangeComponent(3));
    Assets.generateAsset(
        new AssetUri(AssetType.PREFAB, "test:prefabWithRetainedComponent"),
        prefabData,
        Prefab.class);
    blockWithRetainedComponent.setPrefab("test:prefabWithRetainedComponent");
    blockManager.addBlockFamily(
        new SymmetricFamily(
            new BlockUri("test:blockWithRetainedComponent"), blockWithRetainedComponent),
        true);

    blockInFamilyOne = new Block();
    blockInFamilyOne.setKeepActive(true);
    blockInFamilyOne.setPrefab("test:prefabWithString");
    blockInFamilyTwo = new Block();
    blockInFamilyTwo.setPrefab("test:prefabWithString");
    blockInFamilyTwo.setKeepActive(true);
    blockManager.addBlockFamily(
        new HorizontalBlockFamily(
            new BlockUri("test:blockFamily"),
            ImmutableMap.<Side, Block>of(
                Side.FRONT,
                blockInFamilyOne,
                Side.LEFT,
                blockInFamilyTwo,
                Side.RIGHT,
                blockInFamilyTwo,
                Side.BACK,
                blockInFamilyOne),
            Collections.<String>emptyList()),
        true);

    keepActiveBlock = new Block();
    keepActiveBlock.setKeepActive(true);
    keepActiveBlock.setPrefab("test:prefabWithString");
    blockManager.addBlockFamily(
        new SymmetricFamily(new BlockUri("test:keepActiveBlock"), keepActiveBlock), true);

    worldProvider.initialise();
  }