Skip to content

Commit

Permalink
Merge pull request #13 from vtt-lair/in_chat
Browse files Browse the repository at this point in the history
feat(chat): show pronouns in chatbox
  • Loading branch information
vtt-lair authored Apr 24, 2022
2 parents 5762aee + d804d08 commit d47cdee
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
"PPRN.Enabled.Hint": "This allows you to select your pronouns on the player configuration.",
"PPRN.ShowPlayerList.Name": "Show pronouns in Player List",
"PPRN.ShowPlayerList.Hint": "This will add the entered pronouns after the player name, but before the character name in the Player List",
"PPRN.ShowPlayerPronounChat.Name": "Show pronouns next to player name in chat",
"PPRN.ShowPlayerPronounChat.Hint": "This will add the entered pronouns after the player name in the chatbox",
"PPRN.CharacterEnabled.Name": "Enable Character Pronouns",
"PPRN.CharacterEnabled.Hint": "This allows you to select your own pronouns on the player configuration per character.",
"PPRN.ShowCharacterPronoun.Name": "Show character pronouns in Player List",
"PPRN.ShowCharacterPronoun.Hint": "This will add the entered pronouns after the character name in the Player List",
"PPRN.ShowCharacterPronounChat.Name": "Show character pronouns after character name in chat",
"PPRN.ShowCharacterPronounChat.Hint": "This will add the entered pronouns after the character name in the chatbox",
"PPRN.SavePronounToGenderField.Name": "Save the selected character pronouns to the gender field",
"PPRN.SavePronounToGenderField.Hint": "This will save the selected character pronouns to the gender field on the actor. This might not save to the correct field on your actor depending on the game system. Please inform me if it's not working for you specific system.",
"PPRN.Label": "Player Pronouns",
Expand Down
Binary file added player-pronouns-v0.1.7.zip
Binary file not shown.
41 changes: 41 additions & 0 deletions scripts/player-pronouns.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ let pronounsEnabled = false;
let characterPronounsEnabled = false;
let showCharacterPronoun = false;
let saveToGender = false;
let showPlayerPronounChat = false;
let showCharacterPronounChat = false;
let listOfPronouns = [];
let systemDefinedGenderField = '';

Expand Down Expand Up @@ -248,12 +250,32 @@ const PlayerPronouns = {
}
},

renderChatMessage(chatMessage, html) {
const sender = html?.[0]?.querySelector(`.message-sender`).innerText;
let pronoun = '';

if (sender) {
if (chatMessage?.data?.speaker?.actor && showCharacterPronounChat) {
pronoun = `${PlayerPronouns.getPronoun(game.actors.get(chatMessage?.user?.data?.character), 'character-pronoun')}`.trim();
} else if (showPlayerPronounChat) {
pronoun = `${PlayerPronouns.getPronoun(chatMessage?.user, 'pronoun')}`.trim();
}

if (pronoun) {
pronoun = ` (${pronoun})`;
}
html[0].querySelector(`.message-sender`).innerText = `${sender}${pronoun}`;
}
},

grabSavedSettings() {
pronounsEnabled = game.settings.get("player-pronouns", "enabled");
showPlayerList = game.settings.get("player-pronouns", "showPlayerList");
characterPronounsEnabled = game.settings.get("player-pronouns", "characterEnabled");
showCharacterPronoun = game.settings.get("player-pronouns", "showCharacterPronoun");
saveToGender = game.settings.get("player-pronouns", "saveToGender");
showPlayerPronounChat = game.settings.get("player-pronouns", "showPlayerPronounChat");
showCharacterPronounChat = game.settings.get("player-pronouns", "showCharacterPronounChat");

listOfPronouns = game.settings.get("player-pronouns", "pronounsList");
if (listOfPronouns?.length === 1) {
Expand All @@ -265,6 +287,7 @@ const PlayerPronouns = {
Hooks.on("renderUserConfig", PlayerPronouns.onConfigRender);
Hooks.on("closeUserConfig", PlayerPronouns.onConfigUpdate);
Hooks.on("renderPlayerList", PlayerPronouns.renderPlayerList);
Hooks.on("renderChatMessage", PlayerPronouns.renderChatMessage);
},

setupGenderVariable() {
Expand Down Expand Up @@ -334,6 +357,15 @@ function registerPlayerPronounsSettings() {
config: true,
});

game.settings.register("player-pronouns", "showPlayerPronounChat", {
name: game.i18n.localize("PPRN.ShowPlayerPronounChat.Name"),
hint: game.i18n.localize("PPRN.ShowPlayerPronounChat.Hint"),
scope: "world",
type: Boolean,
default: false,
config: true,
});

game.settings.register("player-pronouns", "characterEnabled", {
name: game.i18n.localize("PPRN.CharacterEnabled.Name"),
hint: game.i18n.localize("PPRN.CharacterEnabled.Hint"),
Expand All @@ -352,6 +384,15 @@ function registerPlayerPronounsSettings() {
config: true,
});

game.settings.register("player-pronouns", "showCharacterPronounChat", {
name: game.i18n.localize("PPRN.ShowCharacterPronounChat.Name"),
hint: game.i18n.localize("PPRN.ShowCharacterPronounChat.Hint"),
scope: "world",
type: Boolean,
default: false,
config: true,
});

game.settings.register("player-pronouns", "saveToGender", {
name: game.i18n.localize("PPRN.SavePronounToGenderField.Name"),
hint: game.i18n.localize("PPRN.SavePronounToGenderField.Hint"),
Expand Down

0 comments on commit d47cdee

Please sign in to comment.