Skip to content

Commit

Permalink
Add emotes setting (#66)
Browse files Browse the repository at this point in the history
* Added config for emotes

* Add odaDap emote

* Add OdaCap emote

* Improve emote list and add ignore list
  • Loading branch information
DapperMickie authored Jun 18, 2024
1 parent ae34a25 commit d3d8753
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,34 @@ default boolean snowballed()
return true;
}

@ConfigItem(
keyName = "emotes",
name = "Emotes",
description = "Configures whether or not some of the text in game gets replaced with Odablock's emotes.<br />type '::odaemotes' in chat to see a list of all available emotes.",
position = 32
)
default boolean emotes()

@ConfigItem(
keyName = "emoteIgnoreList",
name = "Emote Ignore List",
description = "A comma separated list of emotes to ignore for example: \":p, :)\".<br />type '::odaemotes' in chat to see a list of all available emotes.",
position = 33
)
default String emoteIgnoreList()
{
return "";
}

@ConfigItem(
keyName = "warriors",
name = "Odablock Warriors",
description = "Should the '7th Realm' in-game sound be replaced with the Odablock Warriors song?",
position = 30,
position = 34,
warning = "If you turn this off, you'll have to reload the client to be able to manually play '7th Realm' again."
)
default boolean warriors()

{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.awt.image.BufferedImage;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.runelite.client.util.ImageUtil;

@AllArgsConstructor
Expand All @@ -24,6 +25,8 @@ public enum Emote
SMILE(":)", EmoteType.GIF, new String[]{"smile"}),
TUNE("tune", EmoteType.GIF),
ODAWHAT("odawhat", EmoteType.PNG),
DAP("dap", EmoteType.PNG),
CAP("cap", EmoteType.PNG),
WHENITREGISTERS("whenitregisters", EmoteType.GIF),
WINK("wink", EmoteType.PNG);

Expand All @@ -35,8 +38,10 @@ private enum EmoteType

private static final Map<String, Emote> emojiMap;

@Getter
private final String trigger;
private final EmoteType emoteType;
@Getter
private final String[] altTriggers;

Emote(final String trigger, EmoteType emoteType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.github.dappermickie.odablock.emotes;

import com.github.dappermickie.odablock.OdablockConfig;
import static com.github.dappermickie.odablock.OdablockPlugin.ODABLOCK;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import javax.inject.Inject;
Expand Down Expand Up @@ -34,6 +38,9 @@ public class EmoteHandler
@Inject
private Client client;

@Inject
private OdablockConfig config;

private int[] iconIds;

public void loadEmotes()
Expand All @@ -56,6 +63,11 @@ public void loadEmotes()

public void onChatMessage(ChatMessage chatMessage)
{
if (!config.emotes())
{
return;
}

if (iconIds == null)
{
return;
Expand Down Expand Up @@ -91,6 +103,11 @@ public void onChatMessage(ChatMessage chatMessage)

public void onOverheadTextChanged(final OverheadTextChanged event)
{
if (!config.emotes())
{
return;
}

if (!(event.getActor() instanceof Player))
{
return;
Expand Down Expand Up @@ -122,14 +139,51 @@ private void sendOdaEmotes()
{
final int emoteId = iconIds[emote.ordinal()];
final String emoteImage = "<img=" + chatIconManager.chatIconIndex(emoteId) + ">";
client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, emote.name() + " : " + emoteImage, null);
StringBuilder chatMessageSb = new StringBuilder();
chatMessageSb.append(emote.getTrigger());
chatMessageSb.append(" : ");
chatMessageSb.append(emoteImage);
List<String> altTriggerOriginal = Arrays.asList(emote.getAltTriggers());
List<String> altTriggers = new ArrayList<>(altTriggerOriginal);
if (!emote.getTrigger().startsWith("oda") && !emote.getTrigger().startsWith(":"))
{
altTriggers.add("oda" + emote.getTrigger());
}
for (int i = 0; i < altTriggers.size(); i++)
{
if (i == 0)
{
chatMessageSb.append(" (alt: ");
}
else
{
chatMessageSb.append(", ");
}
String altTrigger = altTriggers.get(i);
chatMessageSb.append(altTrigger);
if (!altTrigger.startsWith("oda") && !altTrigger.startsWith(":"))
{
chatMessageSb.append(", oda");
chatMessageSb.append(altTrigger);
}
if (i == (altTriggers.size() - 1))
{
chatMessageSb.append(" )");
}
}
client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, chatMessageSb.toString(), null);
}
client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, "Some emotes have an alternative trigger that will get translated into an emote.", null);
client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, "For example: both \"cap\" and \"odacap\" work.", null);
client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, "To disable an emote, you can add it to the \"Emote Ignore List\" in the plugin settings.", null);
client.addChatMessage(ChatMessageType.GAMEMESSAGE, ODABLOCK, "Add the emote and the alternative triggers to completely disable an emote.", null);
}

@Nullable
String updateMessage(final String message)
{
final String[] messageWords = WHITESPACE_REGEXP.split(message);
final String[] ignoredEmotes = config.emoteIgnoreList().split(",");

boolean editedMessage = false;
for (int i = 0; i < messageWords.length; i++)
Expand All @@ -144,6 +198,21 @@ String updateMessage(final String message)
continue;
}

boolean shouldSkip = false;
for (String ignored : ignoredEmotes)
{
if (ignored.strip().equalsIgnoreCase(trigger))
{
shouldSkip = true;
break;
}
}

if (shouldSkip)
{
break;
}

final int emoteId = iconIds[emote.ordinal()];
messageWords[i] = messageWords[i].replace(originalTrigger, "<img=" + chatIconManager.chatIconIndex(emoteId) + ">");
editedMessage = true;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d3d8753

Please sign in to comment.