Skip to content

Commit

Permalink
feat: DetailPopupView 작성, setTimeout 함수 추가 #14
Browse files Browse the repository at this point in the history
  • Loading branch information
yuncoffee committed Mar 28, 2023
1 parent ff8c175 commit a9ecc15
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 23 deletions.
61 changes: 43 additions & 18 deletions Data/Global/globalStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,48 @@ enum EnumSpeaker: CaseIterable {
case autodoor
}

enum EnumDetailImage: CaseIterable {
case joljol
case autodoor
case key1 // 주머니에 열쇠가 들어있다.
case key2 // 컬러스왑한 열쇠가 6개가 있다.
case key3 // 열쇠 중 1개(커피)를 선택한다.
}

class GlobalStore: ObservableObject {
/**
현재 Scene을 구분하기 위한 enum
*/
@Published
var currentScene = EnumScene.opeaning

var currentScene = EnumScene.opeaning {
didSet {
scriptCount = 0
}
}
/**
현재 스크립트를 말하는 대상을 구분하기 위한 enum
*/
@Published
var currentSpeaker = EnumSpeaker.system

/**
현재 오브젝트의 디테일 이미지를 보여주는 팝업뷰가 열려있는지 확인하기 위한 변수
*/
@Published
var isPopupActive = false {
didSet{
if isPopupActive == true {
DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
self.isPopupActive = false
}
}
}
}

var isPopupActive = false
@Published
/**
씬 별로 스크립트 진행도를 표현하기 위한 변수
*/
var scriptCount = 0

init() {
print("globalStore is ready")
}

func updateCurrentScene (scene: EnumScene){
currentScene = scene
}
}

protocol ObservableStore: ObservableObject {}

// currentSpeaker
extension GlobalStore: ObservableStore {

func updateCurrentSpeaker(speaker: EnumSpeaker){
Expand All @@ -78,3 +82,24 @@ extension GlobalStore: ObservableStore {
currentSpeaker = EnumSpeaker.system
}
}

// currentScene
extension GlobalStore {
func updateCurrentScene (scene: EnumScene){
currentScene = scene
}
}

// isPopupActive
extension GlobalStore {
func toggleIsPopupActive(){
isPopupActive.toggle()
}
}

// scriptCount
extension GlobalStore {
func addScriptCount() {
scriptCount += 1
}
}
15 changes: 15 additions & 0 deletions Utils/Timeout/setTimeout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// File.swift
//
//
// Created by Yun Dongbeom on 2023/03/28.
//

import Foundation


public func setTimeoutClosure(timeCount: Int, completion: @escaping ()->()) {
DispatchQueue.main.asyncAfter(deadline: .now() + DispatchTimeInterval.seconds(timeCount)) {
completion()
}
}
9 changes: 7 additions & 2 deletions View/DetailPopupView/DetailPopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import SwiftUI
2. 값을 받아서 다른 이미지를 보여준다.
*/
struct DetailPopupView: View {
var target: EnumDetailImage = .key1

private let IMAGE_PATH = "Frame_290_290"
private let IMAGE_SIZE: CGFloat = 290

var body: some View {
Image("Frame_Mission_290_290")
.frame(width: 290, height: 290)
Image("\(IMAGE_PATH)_\(target)")
.frame(width: IMAGE_SIZE, height: IMAGE_SIZE)
}
}

4 changes: 3 additions & 1 deletion View/SceneView/SceneView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct SceneView: View {
var globalStore: GlobalStore

private func delayText() {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
setTimeoutClosure(timeCount: 3) {
globalStore.isPopupActive = true
}
}
Expand All @@ -35,6 +35,8 @@ struct SceneView: View {
print(globalStore.currentSpeaker)
delayText()
}
}else if globalStore.currentScene == .sequence1 {
SequenceOneView()
}
if globalStore.isPopupActive {
DetailPopupView()
Expand Down
2 changes: 0 additions & 2 deletions View/ScriptBoxView/ScriptBoxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ struct ScriptBoxView: View {
VStack(alignment: .leading) {
HStack(spacing: 0){
VStack(alignment: .leading, spacing: 0){
// Text(scripts[scriptCount])
// .frame(width: width - 32)
CustomText(value: "\(EnumSpeaker.coffee)", fontSize: 24)
.padding(.bottom, 4)
CustomText(value: "내 열쇠와 색이 같은 문을 열고 들어가보자.")
Expand Down

0 comments on commit a9ecc15

Please sign in to comment.