Skip to content

Commit

Permalink
✨ emote parameter for !drop command
Browse files Browse the repository at this point in the history
  • Loading branch information
haliphax committed Oct 3, 2023
1 parent f8549d7 commit 7c1def1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ connected. Some require that the user be either a moderator or the broadcaster.
| --------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------- |
| `!clearscores [username] [username...]` | Moderator | Reset the overlay's localStorage, clearing score records. If no usernames are provided, all records are wiped. |
| `!commands` | Everyone | A link to this README section. |
| `!drop` | Everyone | Play the game! |
| `!drop [emote]` | Everyone | Play the game! |
| `!droplow` | Everyone | Show the lowest score from the last 24 hours. |
| `!droprecent` | Everyone | Show the most recent drop scores. |
| `!droptop` | Everyone | Show the top score from the last 24 hours. |
Expand Down
24 changes: 13 additions & 11 deletions src/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,33 @@ export default class Avatar {
chute: Phaser.GameObjects.Image;
chuteGravity: integer;
container: Phaser.GameObjects.Container;
customImage = false;
label: Phaser.GameObjects.Text | null;
rect?: Phaser.GameObjects.Rectangle;
score: integer;
scoreLabel: Phaser.GameObjects.Text | null;
sprite: Phaser.GameObjects.Image;
spriteNumber: integer;
swayTween: Tweens.Tween | null = null;
username: string;

constructor(username: string, game: Phaser.Scene) {
constructor(username: string, game: Phaser.Scene, emote?: string) {
this.username = username;
this.chute = game.add
.image(0, 0, "chute")
.setOrigin(0.5, 1)
.setVisible(false);
/*
this.chute.angle =
Math.random() * constants.MAX_SWAY * (Math.random() < 0.5 ? -1 : 1);
*/
this.chuteGravity = parseInt(hs.gravity_chute || constants.GRAVITY_CHUTE);
this.spriteNumber = Math.ceil(Math.random() * constants.NUM_SPRITES);
this.sprite = game.add
.image(0, 0, `drop${this.spriteNumber}`)
.setOrigin(0.5, 0.5)
.setVisible(false);

if (emote) {
this.customImage = true;
this.sprite = game.add.image(0, 0, emote);
this.sprite.setDisplaySize(64, 64);
} else {
const spriteNumber = Math.ceil(Math.random() * constants.NUM_SPRITES);
this.sprite = game.add.image(0, 0, `drop${spriteNumber}`);
}

this.sprite.setOrigin(0.5, 0.5).setVisible(false);
this.label = game.add
.text(0, -(this.sprite.height / 2) - constants.LABEL_SIZE, username, {
fontFamily: `"${constants.FONT_FAMILY}"`,
Expand Down
34 changes: 29 additions & 5 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export default class Game extends Phaser.Scene {
this.load.image("drop4", "drop4.png");
this.load.image("drop5", "drop5.png");
this.load.image("pad", "pad.png");
/*
this.load.setBaseURL();
this.load.image(
"emotesv2_ffbe3ae7fb2e47bbafa9d9557bb117ed",
"https://static-cdn.jtvnw.net/emoticons/v2/emotesv2_ffbe3ae7fb2e47bbafa9d9557bb117ed/default/dark/3.0",
);
*/
}

create() {
Expand Down Expand Up @@ -237,7 +244,7 @@ export default class Game extends Phaser.Scene {

// events

onDrop(username: string, queue = false) {
onDrop(username: string, queue = false, emote?: string) {
if (!this.active && !this.queue) this.start();
else if (this.active && this.queue && !queue) return;

Expand All @@ -251,10 +258,27 @@ export default class Game extends Phaser.Scene {
}

clearTimeout(this.endTimer);
const avatar = new Avatar(username, this);
this.droppers.set(username, avatar);
this.droppersArray.push(avatar);
this.dropGroup!.add(avatar.container);

const finish = () => {
const avatar = new Avatar(username, this, emote);
this.droppers.set(username, avatar);
this.droppersArray.push(avatar);
this.dropGroup!.add(avatar.container);
};

if (emote) {
const emoteUrl = `https://static-cdn.jtvnw.net/emoticons/v2/${emote}/default/dark/3.0`;

this.load.setBaseURL();
this.load
.image(emote, emoteUrl)
.on(`filecomplete-image-${emote}`, () => finish())
.start();

return;
}

finish();
}

onDropLow() {
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,16 @@ twitch.on(
`@${tags.username} -> Drop game commands: https://github.com/haliphax/drop-game/blob/main/README.md#commands`,
);
break;
case "drop":
emitter.emit("drop", tags["display-name"]);
case "drop": {
let emote: string | undefined = undefined;

if (tags.emotes) {
emote = Object.keys(tags.emotes)[0];
}

emitter.emit("drop", tags["display-name"], false, emote);
break;
}
case "droplow":
emitter.emit("droplow");
break;
Expand Down

0 comments on commit 7c1def1

Please sign in to comment.