You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.5 KiB
92 lines
2.5 KiB
/*
|
|
* Copyright (C) 2024 jimj316
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package moe.nekojimi.chords;
|
|
|
|
import com.amihaiemil.eoyaml.Yaml;
|
|
import com.amihaiemil.eoyaml.YamlInput;
|
|
import com.amihaiemil.eoyaml.YamlMapping;
|
|
import com.amihaiemil.eoyaml.YamlPrinter;
|
|
import java.io.File;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
|
|
/**
|
|
*
|
|
* @author jimj316
|
|
*/
|
|
public class Soundboard
|
|
{
|
|
|
|
private final Chords bot;
|
|
private final Map<String, Track> sounds = new HashMap<>();
|
|
|
|
public Soundboard(Chords bot)
|
|
{
|
|
this.bot = bot;
|
|
}
|
|
|
|
public void loadYAML(File file) throws IOException
|
|
{
|
|
if (!file.exists())
|
|
return;
|
|
YamlInput input = Yaml.createYamlInput(file);
|
|
YamlMapping mapping = input.readYamlMapping();
|
|
sounds.putAll(Util.yamlMappingToMap(mapping, (t) -> Track.fromYaml(t.asMapping())));
|
|
}
|
|
|
|
public void saveYAML(File file) throws IOException
|
|
{
|
|
YamlPrinter printer = Yaml.createYamlPrinter(new FileWriter(file));
|
|
printer.print(Util.mapToMapping(sounds, (t) -> t.toYaml()));
|
|
}
|
|
|
|
public void add(String emoji, Track t)
|
|
{
|
|
t.setKept(true);
|
|
sounds.put(emoji, t);
|
|
}
|
|
|
|
public boolean remove(String emoji)
|
|
{
|
|
if (!sounds.containsKey(emoji))
|
|
return false;
|
|
Track t = sounds.get(emoji);
|
|
t.setKept(false);
|
|
t.delete();
|
|
sounds.remove(emoji);
|
|
return true;
|
|
}
|
|
|
|
public boolean play(String emoji)
|
|
{
|
|
if (!sounds.containsKey(emoji))
|
|
return false;
|
|
if (bot.getMusicHandler() == null)
|
|
return false;
|
|
final Track track = sounds.get(emoji);
|
|
track.setKept(true);
|
|
bot.getMusicHandler().play(track);
|
|
return true;
|
|
}
|
|
|
|
public List<String> getEmoji()
|
|
{
|
|
return new ArrayList<>(sounds.keySet());
|
|
}
|
|
|
|
}
|
|
|