-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to Emote Popups and Animation Component (#36)
* Emote Popup Enhancements Made Emotes jump higher on average Added emote zone that adjusts amounts of emotes displayed based on usage * Overhauled animation component Duration is now in ms Display waits for content loaded Supports image and video types
- Loading branch information
1 parent
e1cca0b
commit 81c97e9
Showing
11 changed files
with
231 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="animation-display"> | ||
<div class="vertical"> | ||
<ng-template animationSpace></ng-template> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Component, Directive, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; | ||
import { BotConnectorService } from '../services/bot-connector.service'; | ||
import { AnimationComponent } from './animation.component'; | ||
|
||
@Directive({ | ||
selector: '[animationSpace]', | ||
}) | ||
export class AnimationHostDirective { | ||
constructor(public viewContainerRef: ViewContainerRef) { } | ||
} | ||
|
||
@Component({ | ||
selector: 'app-animation-host', | ||
templateUrl: './animation-host.component.html', | ||
styleUrls: ['./animation.component.scss'] | ||
}) | ||
export class AnimationHostComponent implements OnInit { | ||
|
||
@ViewChild(AnimationHostDirective, { static: true }) animationSpace!: AnimationHostDirective; | ||
|
||
constructor(private botService: BotConnectorService) { } | ||
|
||
ngOnInit(): void { | ||
this.botService.getStream('streamdeck').subscribe(data => { | ||
if (data.type === "animation") { | ||
|
||
const viewContainerRef = this.animationSpace.viewContainerRef; | ||
const componentRef = viewContainerRef.createComponent<AnimationComponent>(AnimationComponent); | ||
|
||
let source = data.source; | ||
|
||
//typescript compiler is drunk, just leave it | ||
if ("canParse" in URL && typeof URL.canParse == "function") { | ||
if (URL.canParse(source)) { | ||
let url = new URL(source); | ||
//adding a random bit of get query so the browser doesn't try to cache our stuff | ||
url.searchParams.append("random", Date.now().toString()); | ||
source = url.href; | ||
} | ||
|
||
} | ||
|
||
componentRef.instance.source = source; | ||
componentRef.instance.contentLoadedCallack = function() { | ||
setTimeout(() => { | ||
componentRef.destroy(); | ||
}, data.duration); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
<ng-container *ngIf="display"> | ||
<div class="animation-display"> | ||
<div class="vertical"> | ||
<img class="animation" src="{{source}}"/> | ||
</div> | ||
</div> | ||
</ng-container> | ||
<div class=""> | ||
<img [hidden]="!image" class="animation" src="{{source}}" (load)="_imageLoaded()"> | ||
<video #videoPlayer [hidden]="!video" class="animation" autoplay muted> | ||
<source src="{{source}}"> | ||
</video> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,48 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { BotConnectorService } from '../services/bot-connector.service'; | ||
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild, ViewContainerRef } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-animation', | ||
templateUrl: './animation.component.html', | ||
styleUrls: ['./animation.component.scss'] | ||
}) | ||
export class AnimationComponent implements OnInit { | ||
display: boolean = false; | ||
export class AnimationComponent implements OnDestroy, AfterViewInit { | ||
source: string = ""; | ||
image = false; | ||
video = false; | ||
playing = false; | ||
|
||
constructor(private botService: BotConnectorService) { } | ||
contentLoadedCallack!: Function; | ||
|
||
ngOnInit(): void { | ||
this.botService.getStream('streamdeck').subscribe(data => { | ||
if (data.type === "animation") { | ||
this.display = true; | ||
this.source = data.source; | ||
@ViewChild('videoPlayer') videoPlayer!: ElementRef; | ||
|
||
setTimeout(() => { | ||
this.display = false; | ||
}, data.duration * 1000); | ||
} | ||
}); | ||
constructor(public viewContainerRef: ViewContainerRef) { } | ||
|
||
ngAfterViewInit(): void { | ||
this.videoPlayer.nativeElement.onloadeddata = this._videoLoaded.bind(this); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.playing = false; | ||
this.image = false; | ||
this.video = false; | ||
this.source = ""; | ||
} | ||
|
||
_imageLoaded() { | ||
if (this.playing) return; | ||
this.playing = true; | ||
this.image = true; | ||
this.contentLoaded(); | ||
} | ||
|
||
_videoLoaded() { | ||
if (this.playing) return; | ||
this.playing = true; | ||
this.video = true; | ||
this.contentLoaded(); | ||
} | ||
|
||
contentLoaded(): void { | ||
this.contentLoadedCallack(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/app/emote-popups/subclasses/emote-popups-multiple.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Component } from '@angular/core'; | ||
import { EmotePopupsComponent, EmoteProperties } from '../emote-popups.component'; | ||
|
||
@Component({ | ||
selector: 'app-emote-popups-multiple', | ||
templateUrl: '../emote-popups.component.html', | ||
styleUrls: ['../emote-popups.component.scss'] | ||
}) | ||
export class EmotePopupsComponentMultiple extends EmotePopupsComponent { | ||
|
||
protected amount = 0; | ||
protected timeframe = 10 * 1000; | ||
protected emoteUsages: { [id: string] : number[] } = {}; | ||
|
||
override adjustEmoteProperties(properties: EmoteProperties): void { | ||
let amountInLastTimeframe = this.findAmountUsedLastTimeframe(properties.asset); | ||
properties.amount = this.amountFunction(amountInLastTimeframe); | ||
} | ||
|
||
findAmountUsedLastTimeframe(emote: string): number { | ||
let now = Date.now(); | ||
let latestTimestampAcceptable = now - this.timeframe; | ||
|
||
let usages = this.emoteUsages[emote]; | ||
if (!usages) { | ||
usages = []; | ||
} | ||
usages = usages.filter((e) => { | ||
return e >= latestTimestampAcceptable; | ||
}); | ||
let result = usages.length; | ||
|
||
usages.push(now); | ||
this.emoteUsages[emote] = usages; | ||
|
||
return result; | ||
} | ||
|
||
amountFunction(amountInLastTimeframe: number): number { | ||
let hist = amountInLastTimeframe; | ||
|
||
let a = 2, b = 2, c = -0.4, d = 1, e = 1; | ||
let result = Math.pow(a, c*hist+d) * b + e; | ||
|
||
result = Math.round(result); | ||
|
||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.