Skip to content

Commit

Permalink
feat(chat card): add card reroll functionality (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
MangoFVTT authored Nov 20, 2024
1 parent 932f96b commit fdc175d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/style/chat/module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@
position: static;

button {
width: 44px;
width: 46px;
height: 22px;
font-size: var(--font-size-14);
font-weight: 600;
Expand Down
24 changes: 24 additions & 0 deletions src/system/documents/chat-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export class CosmereChatMessage extends ChatMessage {
.find('.message-metadata')
.find('.message-delete');
if (!game.user!.isGM) deleteButton?.remove();

html.find('.message-repeat').on('click', (event) => {
void this.onClickRepeat(event);
});
}

protected async enrichCardContent(html: JQuery) {
Expand Down Expand Up @@ -590,6 +594,26 @@ export class CosmereChatMessage extends ChatMessage {
toggle.siblings('.dice-subtotal').removeClass('active');
}

/**
* Handles a repeat button click event.
* @param {JQuery.ClickEvent} event The originating event of the button click.
*/
private async onClickRepeat(event: JQuery.ClickEvent) {
event.preventDefault();
event.stopPropagation();

const clone = await Promise.all(
this.rolls.map(async (roll) => await roll.reroll()),
);

void ChatMessage.create({
user: game.user!.id,
speaker: this.speaker,
flags: this.flags,
rolls: clone,
});
}

/**
* Handles an apply button click event.
* @param {JQuery.ClickEvent} event The originating event of the button click.
Expand Down

0 comments on commit fdc175d

Please sign in to comment.