示例#1
0
 @Override
 public boolean match(FileHandle file) {
   boolean result =
       (file.extension().equals("ogg")
               || file.extension().equals("wav")
               || file.extension().equals("mp3"))
           && (file.path().contains("music") || file.path().contains("musics"));
   if (result) Engine.getAssetManager().load(file.path().replace("\\", "/"), Music.class);
   return result;
 }
示例#2
0
  @Override
  public void testWorker() {
    FileHandle directory = Gdx.files.external("");
    dstFile =
        ProjectUtils.getNonExistentFile(
            directory, image.nameWithoutExtension() + "1", image.extension());
    controller.action(ExecuteWorker.class, DownloadFile.class, false, this, URL, dstFile);

    dstFile2 =
        ProjectUtils.getNonExistentFile(
            directory, image.nameWithoutExtension() + "2", image.extension());
    controller.action(ExecuteWorker.class, DownloadFile.class, false, this, image.read(), dstFile2);
  }
示例#3
0
  /**
   * Loads the 3d meshes located at path
   *
   * @param path
   */
  private static void Load3DMeshes(final String path) {
    AssetManager assetManager = VictusLudusGame.engine.assetManager;

    FileHandle meshFolder = VFile.getFileHandle(path);
    FileHandle[] files = VFile.getFiles(meshFolder);

    for (FileHandle file : files) {
      if (file.exists()
          && (file.extension().toLowerCase().equals("obj")
              || file.extension().toLowerCase().equals("g3db")
              || file.extension().toLowerCase().equals("g3dj"))) {
        assetManager.load(file.path(), Model.class);
        System.out.println("queueing " + file.path());
      }
    }
  }
  @Override
  public void fileChanged(FileHandle file) {
    String relativePath = fileAccess.relativizeToAssetsFolder(file);

    if (ProjectPathUtils.isTexture(relativePath, file.extension())) {
      cacheWaitTimer.clear();
      cacheWaitTimer.scheduleTask(
          new Task() {
            @Override
            public void run() {
              updateCache();
            }
          },
          0.5f);
    }

    if (ProjectPathUtils.isTextureAtlas(file, relativePath)) {
      atlasWaitTimer.clear();
      cacheWaitTimer.scheduleTask(
          new Task() {
            @Override
            public void run() {
              updateAtlas(file);
            }
          },
          0.5f);
    }
  }
示例#5
0
  /**
   * Loads the music located at path
   *
   * @param path
   */
  private static void LoadMusic(final String path) {
    AssetManager assetManager = VictusLudusGame.engine.assetManager;

    FileHandle musicFolder = VFile.getFileHandle(path);
    FileHandle[] files = VFile.getFiles(musicFolder);

    for (FileHandle file : files) {
      if (file.exists() && file.extension().toLowerCase().equals("wav")) {
        assetManager.load(file.path(), Music.class);
        System.out.println("queueing " + file.path());
      }
    }
  }
示例#6
0
 public OpenALMusic newMusic(FileHandle file) {
   if (file == null) throw new IllegalArgumentException("file cannot be null.");
   Class<? extends OpenALMusic> musicClass =
       extensionToMusicClass.get(file.extension().toLowerCase());
   if (musicClass == null)
     throw new GdxRuntimeException("Unknown file extension for music: " + file);
   try {
     return musicClass
         .getConstructor(new Class[] {OpenALAudio.class, FileHandle.class})
         .newInstance(this, file);
   } catch (Exception ex) {
     throw new GdxRuntimeException(
         "Error creating music " + musicClass.getName() + " for file: " + file, ex);
   }
 }
  @Override
  public void init() {
    settings = new Settings();
    settings.maxWidth = 4096;
    settings.maxHeight = 4096;
    settings.combineSubdirectories = true;
    settings.silent = true;
    settings.useIndexes = false;
    settings.fast = true;

    loadingRegion = Assets.icons.findRegion("refresh-big");
    missingRegion = Assets.icons.findRegion("file-question-big");

    FileHandle out = fileAccess.getModuleFolder(".textureCache");
    cachePath = out.path();
    cacheFile = out.child("cache.atlas");

    gfxPath = fileAccess.getAssetsFolder().child("gfx").path();
    atlasesFolder = fileAccess.getAssetsFolder().child("atlas");

    watcher.addListener(this);

    try {
      if (cacheFile.exists()) cache = new TextureAtlas(cacheFile);
    } catch (Exception e) {
      Log.error("Error while loading texture cache, texture cache will be regenerated");
    }

    try {
      if (atlasesFolder.exists()) {
        FileHandle[] files = atlasesFolder.list();

        for (FileHandle file : files) if (file.extension().equals("atlas")) updateAtlas(file);
      }
    } catch (Exception e) {
      Log.error("Error encountered while loading one of atlases");
      Log.exception(e);
    }

    updateCache();
  }
示例#8
0
  /**
   * Loads a language from a {@link FileHandle}
   *
   * @param file The {@link FileHandle} of the language file to load
   * @return True on success, otherwise false
   */
  protected static boolean loadFile(FileHandle file) {
    if (!file.isDirectory() && file.extension().equalsIgnoreCase("lang")) {
      try {
        LanguageEntry lang = languages.get(file.name());

        if (lang == null) {
          lang = new LanguageEntry(new Properties());
          languages.put(file.nameWithoutExtension(), lang);
        }

        lang.addProperties(file);

      } catch (Exception io) {
        Gdx.app.error(
            TAG, "Could not load language file with name " + file.nameWithoutExtension(), io);
        return false;
      }

    } else {
      Gdx.app.debug(TAG, "Ignored " + file.name() + " while loading language file");
    }

    return true;
  }
  void loadSkeleton(final FileHandle skeletonFile) {
    if (skeletonFile == null) return;

    try {
      // Setup a texture atlas that uses a white image for images not found in the atlas.
      Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888);
      pixmap.setColor(new Color(1, 1, 1, 0.33f));
      pixmap.fill();
      final AtlasRegion fake = new AtlasRegion(new Texture(pixmap), 0, 0, 32, 32);
      pixmap.dispose();

      String atlasFileName = skeletonFile.nameWithoutExtension();
      if (atlasFileName.endsWith(".json"))
        atlasFileName = new FileHandle(atlasFileName).nameWithoutExtension();
      FileHandle atlasFile = skeletonFile.sibling(atlasFileName + ".atlas");
      if (!atlasFile.exists()) atlasFile = skeletonFile.sibling(atlasFileName + ".atlas.txt");
      TextureAtlasData data =
          !atlasFile.exists() ? null : new TextureAtlasData(atlasFile, atlasFile.parent(), false);
      TextureAtlas atlas =
          new TextureAtlas(data) {
            public AtlasRegion findRegion(String name) {
              AtlasRegion region = super.findRegion(name);
              if (region == null) {
                // Look for separate image file.
                FileHandle file = skeletonFile.sibling(name + ".png");
                if (file.exists()) {
                  Texture texture = new Texture(file);
                  texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
                  region = new AtlasRegion(texture, 0, 0, texture.getWidth(), texture.getHeight());
                  region.name = name;
                }
              }
              return region != null ? region : fake;
            }
          };

      // Load skeleton data.
      String extension = skeletonFile.extension();
      if (extension.equalsIgnoreCase("json") || extension.equalsIgnoreCase("txt")) {
        SkeletonJson json = new SkeletonJson(atlas);
        json.setScale(ui.scaleSlider.getValue());
        skeletonData = json.readSkeletonData(skeletonFile);
      } else {
        SkeletonBinary binary = new SkeletonBinary(atlas);
        binary.setScale(ui.scaleSlider.getValue());
        skeletonData = binary.readSkeletonData(skeletonFile);
        if (skeletonData.getBones().size == 0) throw new Exception("No bones in skeleton data.");
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      ui.toast("Error loading skeleton: " + skeletonFile.name());
      lastModifiedCheck = 5;
      return;
    }

    skeleton = new Skeleton(skeletonData);
    skeleton.setToSetupPose();
    skeleton = new Skeleton(skeleton); // Tests copy constructors.
    skeleton.updateWorldTransform();

    state = new AnimationState(new AnimationStateData(skeletonData));
    state.addListener(
        new AnimationStateAdapter() {
          public void event(TrackEntry entry, Event event) {
            ui.toast(event.getData().getName());
          }
        });

    this.skeletonFile = skeletonFile;
    prefs.putString("lastFile", skeletonFile.path());
    prefs.flush();
    lastModified = skeletonFile.lastModified();
    lastModifiedCheck = checkModifiedInterval;

    // Populate UI.

    ui.window.getTitleLabel().setText(skeletonFile.name());
    {
      Array<String> items = new Array();
      for (Skin skin : skeletonData.getSkins()) items.add(skin.getName());
      ui.skinList.setItems(items);
    }
    {
      Array<String> items = new Array();
      for (Animation animation : skeletonData.getAnimations()) items.add(animation.getName());
      ui.animationList.setItems(items);
    }
    ui.trackButtons.getButtons().first().setChecked(true);

    // Configure skeleton from UI.

    if (ui.skinList.getSelected() != null) skeleton.setSkin(ui.skinList.getSelected());
    setAnimation();

    // ui.animationList.clearListeners();
    // state.setAnimation(0, "walk", true);
  }