Skip to content

Commit

Permalink
Merge pull request #112 from moco-team/feat/new-maze-mechanism
Browse files Browse the repository at this point in the history
Feat/new maze mechanism
  • Loading branch information
LordRonz authored Dec 3, 2023
2 parents 54b38fe + d731f6c commit 0a203c2
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 176 deletions.
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

0 comments on commit 0a203c2

Please sign in to comment.