Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/new maze mechanism #112

Merged
merged 6 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Moco/MocoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct MocoApp: App {

@StateObject private var objectDetectionViewModel = ObjectDetectionViewModel.shared
@StateObject private var arViewModel = ARViewModel()
@StateObject private var motionViewModel = MotionViewModel()
@StateObject private var motionViewModel = MotionViewModel.shared
@StateObject private var orientationInfo = OrientationInfo.shared

private static let sharedModelContainer: ModelContainer = ModelGenerator.generator(false)
Expand Down
2 changes: 2 additions & 0 deletions Moco/Model/MazePromptModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct MazePromptModel {
var isCorrectAnswer: Bool = false
var isWrongAnswer: Bool = false
var isTutorialDone = GlobalStorage.mazeTutorialFinished
var isGameOver = false
var mazeCount = -1
var currentMazeIndex = 0

Expand All @@ -28,6 +29,7 @@ struct MazePromptModel {
progress = 0.0
isCorrectAnswer = false
isWrongAnswer = false
isGameOver = false
isTutorialDone = GlobalStorage.mazeTutorialFinished
mazeCount = -1
currentMazeIndex = 0
Expand Down
27 changes: 25 additions & 2 deletions Moco/View/Components/Prompts/Maze/MazePrompt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import SwiftUI

struct MazePrompt: View {
@Environment(\.navigate) private var navigate
@Environment(\.settingsViewModel) private var settingsViewModel
@Environment(\.audioViewModel) private var audioViewModel
@Environment(\.episodeViewModel) private var episodeViewModel
@Environment(\.mazePromptViewModel) private var mazePromptViewModel

@State private var isCorrectAnswerPopup = false
@State private var isWrongAnswerPopup = false
@State private var gameOverPopup = false

@State private var updateTimer = true
@State private var elapsedSecond = 0
Expand All @@ -30,6 +32,8 @@ struct MazePrompt: View {

var action: () -> Void = {}

var onRestart: (() -> Void)?

func playInitialNarration() {
if mazePromptViewModel.isTutorialDone {
audioViewModel.playSound(
Expand All @@ -49,7 +53,14 @@ struct MazePrompt: View {
Spacer()
TimerView(
durationParamInSeconds: mazePromptViewModel.durationInSeconds
)
) {
// MARK: - Game Over

gameOverPopup = true
mazePromptViewModel.isGameOver = true

// MARK: -
}
.padding(.trailing, Screen.width * 0.3)
}
Text(promptText)
Expand Down Expand Up @@ -112,8 +123,20 @@ struct MazePrompt: View {
.popUp(isActive: $isWrongAnswerPopup, title: "Oh tidak! Kamu pergi ke jalan yang salah", disableCancel: true) {
action()
}
.popUp(
isActive: $gameOverPopup,
title: "Waktu telah habis!",
cancelText: "Keluar",
confirmText: "Ulangi",
disableCancel: true,
type: .danger
) {
onRestart?()
} cancelHandler: {
navigate.popToRoot()
}
.onReceive(timer) { _ in
if updateTimer {
if updateTimer && mazePromptViewModel.isTutorialDone {
elapsedSecond += 1
}
}
Expand Down
Loading
Loading