Search in sources :

Example 1 with SoundResource

use of de.gurkenlabs.litiengine.resources.SoundResource in project litiengine by gurkenlabs.

the class Editor method importSounds.

private void importSounds(File... selectedFiles) {
    for (File file : selectedFiles) {
        try (InputStream stream = new FileInputStream(file.getAbsolutePath())) {
            SoundFormat format = SoundFormat.get(FileUtilities.getExtension(file));
            SoundResource resource = new SoundResource(new BufferedInputStream(stream), FileUtilities.getFileName(file.getName()), format);
            this.getGameFile().getSounds().removeIf(x -> x.getName().equals(resource.getName()));
            this.getGameFile().getSounds().add(resource);
            log.log(Level.INFO, "imported sound {0}", new Object[] { resource.getName() });
        } catch (IOException | UnsupportedAudioFileException e) {
            log.log(Level.SEVERE, e.getMessage(), e);
        }
    }
}
Also used : UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SoundResource(de.gurkenlabs.litiengine.resources.SoundResource) IOException(java.io.IOException) SoundFormat(de.gurkenlabs.litiengine.resources.SoundFormat) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with SoundResource

use of de.gurkenlabs.litiengine.resources.SoundResource in project litiengine by gurkenlabs.

the class AssetPanelItem method exportSound.

private void exportSound() {
    if (!(this.getOrigin() instanceof SoundResource)) {
        return;
    }
    SoundResource sound = (SoundResource) this.getOrigin();
    SoundFormat format = sound.getFormat();
    if (format == SoundFormat.UNSUPPORTED) {
        return;
    }
    FileFilter filter = new FileNameExtensionFilter(format.toString() + " - Sound", format.toString());
    try {
        JFileChooser chooser;
        String source = Editor.instance().getProjectPath();
        chooser = new JFileChooser(source != null ? source : new File(".").getCanonicalPath());
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setDialogType(JFileChooser.SAVE_DIALOG);
        chooser.setDialogTitle("Export Sound");
        chooser.setFileFilter(filter);
        chooser.addChoosableFileFilter(filter);
        chooser.setSelectedFile(new File(sound.getName() + format.toFileExtension()));
        int result = chooser.showSaveDialog(Game.window().getRenderComponent());
        if (result == JFileChooser.APPROVE_OPTION) {
            try (FileOutputStream fos = new FileOutputStream(chooser.getSelectedFile().toString())) {
                fos.write(Codec.decode(sound.getData()));
                log.log(Level.INFO, "exported sound {0} to {1}", new Object[] { sound.getName(), chooser.getSelectedFile() });
            }
        }
    } catch (IOException ex) {
        log.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileOutputStream(java.io.FileOutputStream) SoundResource(de.gurkenlabs.litiengine.resources.SoundResource) IOException(java.io.IOException) SoundFormat(de.gurkenlabs.litiengine.resources.SoundFormat) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)

Example 3 with SoundResource

use of de.gurkenlabs.litiengine.resources.SoundResource in project litiengine by gurkenlabs.

the class AssetPanelItem method deleteAsset.

private void deleteAsset() {
    if (getOrigin() instanceof SpritesheetResource) {
        SpritesheetResource info = (SpritesheetResource) getOrigin();
        int n = getDeleteDialog("spritesheet", info.getName());
        if (n == JOptionPane.OK_OPTION) {
            Editor.instance().getGameFile().getSpriteSheets().remove(getOrigin());
            Resources.images().clear();
            Resources.spritesheets().remove(info.getName());
            Editor.instance().getMapComponent().reloadEnvironment();
            UI.getAssetController().refresh();
        }
    } else if (getOrigin() instanceof EmitterData) {
        EmitterData emitter = (EmitterData) getOrigin();
        int n = getDeleteDialog("emitter", emitter.getName());
        if (n == JOptionPane.OK_OPTION) {
            Editor.instance().getGameFile().getEmitters().remove(getOrigin());
            Editor.instance().getMapComponent().reloadEnvironment();
            UI.getAssetController().refresh();
        }
    } else if (getOrigin() instanceof Blueprint) {
        Blueprint blueprint = (Blueprint) getOrigin();
        int n = getDeleteDialog("blueprint", blueprint.getName());
        if (n == JOptionPane.OK_OPTION) {
            Editor.instance().getGameFile().getBluePrints().remove(getOrigin());
            UI.getAssetController().refresh();
        }
    } else if (getOrigin() instanceof SoundResource) {
        SoundResource sound = (SoundResource) getOrigin();
        int n = getDeleteDialog("sound", sound.getName());
        if (n == JOptionPane.OK_OPTION) {
            Editor.instance().getGameFile().getSounds().remove(getOrigin());
            UI.getAssetController().refresh();
        }
    }
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) SoundResource(de.gurkenlabs.litiengine.resources.SoundResource) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Example 4 with SoundResource

use of de.gurkenlabs.litiengine.resources.SoundResource in project litiengine by gurkenlabs.

the class AssetPanel method loadSounds.

public void loadSounds(List<SoundResource> sounds) {
    this.load(() -> {
        Collections.sort(sounds);
        for (SoundResource sound : sounds) {
            AssetPanelItem panelItem = new AssetPanelItem(Icons.DOC_SOUND, sound.getName(), sound);
            this.add(panelItem);
            panelItem.validate();
        }
    });
}
Also used : SoundResource(de.gurkenlabs.litiengine.resources.SoundResource)

Aggregations

SoundResource (de.gurkenlabs.litiengine.resources.SoundResource)4 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)2 SoundFormat (de.gurkenlabs.litiengine.resources.SoundFormat)2 File (java.io.File)2 IOException (java.io.IOException)2 EmitterData (de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)1 SpritesheetResource (de.gurkenlabs.litiengine.resources.SpritesheetResource)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)1 JFileChooser (javax.swing.JFileChooser)1 FileFilter (javax.swing.filechooser.FileFilter)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1