Implement finish message for detail screen

This commit is contained in:
Dennis Schoepf 2021-08-01 20:31:08 +02:00
parent f98c3e58dc
commit 3633b32b3f
4 changed files with 34 additions and 23 deletions

View file

@ -6,6 +6,8 @@ import { Player } from '../sketchObjects/Player';
import { Revealable, RevealableInterface } from '../sketchObjects/Revealable'; import { Revealable, RevealableInterface } from '../sketchObjects/Revealable';
import store from '../store'; import store from '../store';
import { Coordinates } from '../types'; import { Coordinates } from '../types';
import { CompanionState } from '../ui/companion';
import { Scenes } from './scenes';
export class DetailScene { export class DetailScene {
player: Player; player: Player;
@ -29,8 +31,6 @@ export class DetailScene {
}) })
); );
} }
// TODO: Check if everything was found, if so, get back to overview screen
}); });
} }
@ -45,6 +45,18 @@ export class DetailScene {
}); });
this.player.move(); this.player.move();
if (
this.revealableObjects.every((revObj) => revObj.wasInteractedWith) &&
!(store.getState().companionState === CompanionState.ACTIVE)
) {
store.getState().addUserMessage({
text: "Yaay! You've found all of the important parts of this part of the repository. You will be returned to the subproject overview now. Pick the next subproject you want to take a look at there.",
inputWanted: false,
onNext: () => store.setState({ currentScene: Scenes.OVERVIEW }),
showIdle: false,
});
}
} }
onSceneClick() { onSceneClick() {

View file

@ -117,8 +117,6 @@ export class Revealable {
public onClick() { public onClick() {
if (this.isHovered && !this.wasInteractedWith) { if (this.isHovered && !this.wasInteractedWith) {
console.log('Clicked on Revealable');
this.wasInteractedWith = true; this.wasInteractedWith = true;
store.getState().addInfoMessage({ store.getState().addInfoMessage({
@ -150,8 +148,6 @@ export class Revealable {
let color: any = mp5.color(colors.red); let color: any = mp5.color(colors.red);
console.log(this.pulseCurrentSize, this.pulseCountUp);
if (this.pulseCountUp) { if (this.pulseCountUp) {
this.pulseCurrentSize += 1; this.pulseCurrentSize += 1;
this.pulseOpacity = this.pulseOpacity > 255 ? 255 : this.pulseOpacity - 6; this.pulseOpacity = this.pulseOpacity > 255 ? 255 : this.pulseOpacity - 6;

View file

@ -29,7 +29,9 @@ const store = create<State>(
set((state) => ({ ...state, infoMessages: [...state.infoMessages, newMessage] })), set((state) => ({ ...state, infoMessages: [...state.infoMessages, newMessage] })),
userMessages: [], userMessages: [],
addUserMessage: (newMessage) => addUserMessage: (newMessage) =>
set((state) => ({ ...state, userMessages: [...state.userMessages, newMessage] })), set((state) => ({
userMessages: [...state.userMessages, newMessage],
})),
revealables: [], revealables: [],
setProjectMetadata: (projectName) => setProjectMetadata: (projectName) =>
set((state) => ({ set((state) => ({

View file

@ -12,6 +12,8 @@ export interface CompanionMessage {
text: string; text: string;
inputWanted: boolean; inputWanted: boolean;
timestamp?: number; timestamp?: number;
onNext?: () => void;
showIdle?: boolean;
} }
export class Companion { export class Companion {
@ -41,9 +43,9 @@ export class Companion {
store.subscribe( store.subscribe(
(companionState) => { (companionState) => {
if (companionState === CompanionState.ACTIVE) { if (companionState === CompanionState.ACTIVE) {
this.stopAwaitAnimation();
this.showActiveShape(); this.showActiveShape();
this.scaleUpCompanion(); this.scaleUpCompanion();
this.stopAwaitAnimation();
this.showMessage(this.message); this.showMessage(this.message);
} else if (companionState === CompanionState.IDLE) { } else if (companionState === CompanionState.IDLE) {
this.scaleDownCompanion(); this.scaleDownCompanion();
@ -61,17 +63,14 @@ export class Companion {
(state) => state.companionState (state) => state.companionState
); );
store.subscribe( store.subscribe((state, prevState) => {
(messages: CompanionMessage[], prevMessages: CompanionMessage[]) => { if (prevState.userMessages.length < state.userMessages.length) {
if (prevMessages.length !== messages.length) { const newMessage = state.userMessages[state.userMessages.length - 1];
const newMessage = messages[messages.length - 1];
this.message = newMessage; this.message = newMessage;
store.setState({ companionState: CompanionState.AWAIT }); store.setState({ companionState: CompanionState.ACTIVE });
} }
}, });
(state) => state.userMessages
);
} }
showMessage(message: CompanionMessage) { showMessage(message: CompanionMessage) {
@ -86,16 +85,18 @@ export class Companion {
} }
confirmMessage() { confirmMessage() {
console.log(this.message);
if (this.message.inputWanted) { if (this.message.inputWanted) {
// TODO: Get text from textarea // TODO: Get text from textarea
// TODO: Send via API // TODO: Send via API
} }
// Hide Message // Hide Message
store.setState({ companionState: CompanionState.IDLE });
this.messageRef.style.display = 'none'; this.messageRef.style.display = 'none';
store.setState({ companionState: CompanionState.IDLE });
if (this.message.onNext) {
this.message.onNext();
}
} }
showActiveShape() { showActiveShape() {
@ -163,12 +164,12 @@ export class Companion {
} }
stopAwaitAnimation() { stopAwaitAnimation() {
anime.remove('#companion-await-indicator');
const indicator = document.getElementById('companion-await-indicator'); const indicator = document.getElementById('companion-await-indicator');
indicator.style.display = 'none'; indicator.style.display = 'none';
indicator.style.opacity = '1'; indicator.style.opacity = '1';
indicator.style.transform = 'scale(1) rotate(0)'; indicator.style.transform = 'scale(1) rotate(0)';
anime.remove('#companion-await-indicator');
} }
pupilFollowCursor() { pupilFollowCursor() {