Extend Metronome Plugin with configurable sound and tick delay (#454)

* Extend Metronome Plugin with configurable sound and tick delay
This commit is contained in:
oplosthee
2018-01-27 17:34:46 +01:00
committed by Alexander
parent 210a73bea2
commit 8783f09ecb
2 changed files with 75 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018, SomeoneWithAnInternetConnection
* Copyright (c) 2018, oplosthee <https://github.com/oplosthee>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,13 +28,10 @@ package net.runelite.client.plugins.metronome;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import net.runelite.api.Client;
import net.runelite.api.SoundEffectID;
import net.runelite.api.events.GameTick;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
@@ -42,34 +40,14 @@ import javax.inject.Inject;
)
public class MetronomePlugin extends Plugin
{
private static final Logger logger = LoggerFactory.getLogger(MetronomePlugin.class);
@Inject
Client client;
@Inject
MetronomePluginConfiguration config;
private boolean tock = false;
@Subscribe
void onTick(GameTick tick)
{
if (!config.enabled())
{
return;
}
if (tock)
{
client.playSoundEffect(SoundEffectID.GE_DECREMENT_PLOP);
}
else // tick
{
client.playSoundEffect(SoundEffectID.GE_INCREMENT_PLOP);
}
tock = !tock;
}
private int tickCounter = 0;
private boolean shouldTock = false;
@Provides
MetronomePluginConfiguration provideConfig(ConfigManager configManager)
@@ -77,4 +55,25 @@ public class MetronomePlugin extends Plugin
return configManager.getConfig(MetronomePluginConfiguration.class);
}
@Subscribe
void onTick(GameTick tick)
{
if (!config.enabled() || config.tickCount() == 0)
{
return;
}
if (++tickCounter % config.tickCount() == 0)
{
if (config.enableTock() && shouldTock)
{
client.playSoundEffect(config.tockSound());
}
else
{
client.playSoundEffect(config.tickSound());
}
shouldTock = !shouldTock;
}
}
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018, SomeoneWithAnInternetConnection
* Copyright (c) 2018, oplosthee <https://github.com/oplosthee>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,24 +25,70 @@
*/
package net.runelite.client.plugins.metronome;
import net.runelite.api.SoundEffectID;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup(
keyName = "metronomeplugin",
name = "Metronome plugin",
description = "Configuration for the metronome plugin"
keyName = "metronome",
name = "Metronome",
description = "Plays a sound on the specified tick to aid in efficient skilling"
)
public interface MetronomePluginConfiguration extends Config
{
@ConfigItem(
keyName = "enabled",
name = "Enable metronome",
description = "Toggles tick metronome"
description = "Toggles tick metronome",
position = 1
)
default boolean enabled()
{
return false;
}
@ConfigItem(
keyName = "tickCount",
name = "Tick count",
description = "Configures the tick on which a sound will be played",
position = 2
)
default int tickCount()
{
return 1;
}
@ConfigItem(
keyName = "tickSound",
name = "Tick sound ID",
description = "Configures which sound to play on the specified tick",
position = 3
)
default int tickSound()
{
return SoundEffectID.GE_INCREMENT_PLOP;
}
@ConfigItem(
keyName = "enableTock",
name = "Enable tock (alternating) sound",
description = "Toggles whether to play two alternating sounds",
position = 4
)
default boolean enableTock()
{
return false;
}
@ConfigItem(
keyName = "tockSound",
name = "Tock sound ID",
description = "Configures which sound to alternate between",
position = 5
)
default int tockSound()
{
return SoundEffectID.GE_DECREMENT_PLOP;
}
}