Implement await indicator and message display logic

This commit is contained in:
Dennis Schoepf 2021-07-21 11:05:04 +02:00
parent d471600c0f
commit e62b549185
5 changed files with 59 additions and 14 deletions

View file

@ -11,11 +11,14 @@
<svg xmlns="http://www.w3.org/2000/svg" id="companion-shape" viewBox="0 0 80 80"> <svg xmlns="http://www.w3.org/2000/svg" id="companion-shape" viewBox="0 0 80 80">
<polygon fill="#A60303" points="40,0 68,12 80,40 68,68 40,80 12,68 0,40 12,12"></polygon> <polygon fill="#A60303" points="40,0 68,12 80,40 68,68 40,80 12,68 0,40 12,12"></polygon>
</svg> </svg>
<svg xmlns="http://www.w3.org/2000/svg" id="companion-await-indicator" viewBox="0 0 80 80">
<polygon fill="#A60303" points="40,0 68,12 80,40 68,68 40,80 12,68 0,40 12,12"></polygon>
</svg>
<div id="companion-eye"><div id="companion-pupil"></div></div> <div id="companion-eye"><div id="companion-pupil"></div></div>
<div id="companion-mouth"></div> <div id="companion-mouth"></div>
</div> </div>
<div id="message"> <div id="message">
<div id="message-text">Test</div> <div id="message-text"></div>
<textarea id="message-input" placeholder="Bitte gib einen Text ein ..." /> <textarea id="message-input" placeholder="Bitte gib einen Text ein ..." />
<button type="button" id="message-confirm">Weiter</button> <button type="button" id="message-confirm">Weiter</button>
</div> </div>

View file

@ -35,12 +35,6 @@ export class OverviewScene {
store.setState({ currentScene: edge.scene }); store.setState({ currentScene: edge.scene });
} }
}); });
store.getState().addUserMessage({
text: `Test Message ${Math.random()}`,
inputWanted: false,
timestamp: Date.now(),
});
} }
private drawLocations() { private drawLocations() {

View file

@ -1,4 +1,6 @@
export enum Scenes { export enum Scenes {
OVERVIEW = 'OVERVIEW', OVERVIEW = 'OVERVIEW',
LEGACY = 'LEGACY', LEGACY = 'LEGACY',
PACKAGES = 'PACKAGES',
CONTRIBUTORS = 'CONTRIBUTORS',
} }

View file

@ -34,6 +34,8 @@ export class Companion {
this.ref.addEventListener('mouseover', () => this.handleMouseEnter()); this.ref.addEventListener('mouseover', () => this.handleMouseEnter());
this.ref.addEventListener('mouseleave', () => this.handleMouseLeave()); this.ref.addEventListener('mouseleave', () => this.handleMouseLeave());
this.messageButtonRef.addEventListener('click', () => this.confirmMessage());
this.pupilFollowCursor(); this.pupilFollowCursor();
store.subscribe( store.subscribe(
@ -41,12 +43,16 @@ export class Companion {
if (companionState === CompanionState.ACTIVE) { if (companionState === CompanionState.ACTIVE) {
this.showActiveShape(); this.showActiveShape();
this.scaleUpCompanion(); this.scaleUpCompanion();
this.stopAwaitAnimation();
this.showMessage(this.message);
} else if (companionState === CompanionState.IDLE) { } else if (companionState === CompanionState.IDLE) {
this.scaleDownCompanion(); this.scaleDownCompanion();
this.showIdleShape(); this.showIdleShape();
this.stopAwaitAnimation();
} else if (companionState === CompanionState.AWAIT) { } else if (companionState === CompanionState.AWAIT) {
this.playAwaitAnimation(); this.playAwaitAnimation();
} else if (companionState === CompanionState.SUCCESS) { } else if (companionState === CompanionState.SUCCESS) {
this.stopAwaitAnimation();
this.playSuccessAnimation(); this.playSuccessAnimation();
this.scaleDownCompanion(); this.scaleDownCompanion();
this.showIdleShape(); this.showIdleShape();
@ -59,7 +65,9 @@ export class Companion {
(messages: CompanionMessage[], prevMessages: CompanionMessage[]) => { (messages: CompanionMessage[], prevMessages: CompanionMessage[]) => {
if (prevMessages.length !== messages.length) { if (prevMessages.length !== messages.length) {
const newMessage = messages[messages.length - 1]; const newMessage = messages[messages.length - 1];
this.showMessage(newMessage); this.message = newMessage;
store.setState({ companionState: CompanionState.AWAIT });
} }
}, },
(state) => state.userMessages (state) => state.userMessages
@ -68,18 +76,28 @@ export class Companion {
showMessage(message: CompanionMessage) { showMessage(message: CompanionMessage) {
this.messageTextRef.innerText = message.text; this.messageTextRef.innerText = message.text;
this.messageRef.style.display = 'flex';
if (message.inputWanted) { if (message.inputWanted) {
this.messageInputRef.style.display = 'block'; this.messageInputRef.style.display = 'block';
// TODO: Get text from textarea and log it on confirm, hide button after click on confirm as well
} else { } else {
this.messageInputRef.style.display = 'none'; this.messageInputRef.style.display = 'none';
// TODO: Hide message on confirm click, log time looked at message
} }
} }
confirmMessage() {
console.log(this.message);
if (this.message.inputWanted) {
// Get text from textarea
// Send via API
}
// Hide Message
store.setState({ companionState: CompanionState.IDLE });
this.messageRef.style.display = 'none';
}
showActiveShape() { showActiveShape() {
const mouth = document.getElementById('companion-mouth'); const mouth = document.getElementById('companion-mouth');
mouth.style.opacity = '100%'; mouth.style.opacity = '100%';
@ -130,7 +148,28 @@ export class Companion {
playSuccessAnimation() {} playSuccessAnimation() {}
playAwaitAnimation() {} playAwaitAnimation() {
document.getElementById('companion-await-indicator').style.display = 'inline';
anime({
targets: '#companion-await-indicator',
keyframes: [
{ scale: 4, opacity: 0, rotate: '45deg', duration: 900 },
{ scale: 5, duration: 200 },
],
easing: 'easeOutQuad',
duration: 900,
loop: true,
});
}
stopAwaitAnimation() {
const indicator = document.getElementById('companion-await-indicator');
indicator.style.display = 'none';
indicator.style.opacity = '1';
indicator.style.transform = 'scale(1) rotate(0)';
anime.remove('#companion-await-indicator');
}
pupilFollowCursor() { pupilFollowCursor() {
document.addEventListener('mousemove', (e) => { document.addEventListener('mousemove', (e) => {

View file

@ -45,6 +45,13 @@ button {
width: 40px; width: 40px;
} }
#companion-await-indicator {
height: 40px;
width: 40px;
position: absolute;
right: 0;
}
#companion-mouth { #companion-mouth {
position: absolute; position: absolute;
z-index: 2; z-index: 2;
@ -81,6 +88,7 @@ button {
} }
#message { #message {
display: none;
position: absolute; position: absolute;
right: 60px; right: 60px;
bottom: 50px; bottom: 50px;
@ -89,7 +97,6 @@ button {
border-radius: 10px; border-radius: 10px;
background-color: white; background-color: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.15); box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
display: flex;
flex-direction: column; flex-direction: column;
min-width: 70%; min-width: 70%;