From cc56782dad08538b18ab48e6d9671fb59a0129e1 Mon Sep 17 00:00:00 2001 From: LeeJaeWook <2jae66@gmail.com> Date: Tue, 26 Apr 2022 01:15:45 +0900 Subject: [PATCH 1/4] LiarGame Subject Select View & LiarGame View early Setup --- LiarGame/Sources/Model/LiarSubjectModel.swift | 16 +++ .../Reactor/LiarGameSubjectReactor.swift | 35 +++++ .../LiarGame/LiarGameModeViewController.swift | 2 +- .../LiarGameSubjectViewController.swift | 123 +++++++++++++++++- .../LiarGame/LiarGameViewController.swift | 80 ++++++++++++ xcconfig/LiarGame-Shared.xcconfig | 2 +- 6 files changed, 255 insertions(+), 3 deletions(-) create mode 100644 LiarGame/Sources/Model/LiarSubjectModel.swift create mode 100644 LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift diff --git a/LiarGame/Sources/Model/LiarSubjectModel.swift b/LiarGame/Sources/Model/LiarSubjectModel.swift new file mode 100644 index 0000000..343768f --- /dev/null +++ b/LiarGame/Sources/Model/LiarSubjectModel.swift @@ -0,0 +1,16 @@ +// +// LiarSubjectModel.swift +// LiarGame +// +// Created by Jay on 2022/04/25. +// + +import Foundation + +enum LiarGameSubject{ + case animal + case exercise + case food + case electronicEquipment + case job +} diff --git a/LiarGame/Sources/Reactor/LiarGameSubjectReactor.swift b/LiarGame/Sources/Reactor/LiarGameSubjectReactor.swift index 03ed2d8..0ddf1f8 100644 --- a/LiarGame/Sources/Reactor/LiarGameSubjectReactor.swift +++ b/LiarGame/Sources/Reactor/LiarGameSubjectReactor.swift @@ -6,3 +6,38 @@ // import Foundation +import RxSwift +import RxCocoa +import ReactorKit + + +final class LiarGameSubjectReactor: Reactor{ + enum Action { + case selectSubject(LiarGameSubject) + } + enum Mutation { + case setSubject(LiarGameSubject) + } + struct State { + var selectedSubject: LiarGameSubject? + } + + var initialState = State() + + func mutate(action: Action) -> Observable { + switch action { + case let .selectSubject(subject): + return Observable.just(Mutation.setSubject(subject)) + } + } + + func reduce(state: State, mutation: Mutation) -> State { + switch mutation { + case let .setSubject(subject): + var newState = state + newState.selectedSubject = subject + return newState + } + } + +} diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameModeViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameModeViewController.swift index ead5eb1..2c6c491 100644 --- a/LiarGame/Sources/ViewController/LiarGame/LiarGameModeViewController.swift +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameModeViewController.swift @@ -100,7 +100,7 @@ extension LiarGameModeViewController{ reactor.state.map { $0.mode } .withUnretained(self) .subscribe(onNext: { `self`, mode in - let liarGameSubjectVC = LiarGameSubjectViewController() + let liarGameSubjectVC = LiarGameSubjectViewController(reactor: LiarGameSubjectReactor() ) liarGameSubjectVC.modalPresentationStyle = .fullScreen self.present(liarGameSubjectVC, animated: true, completion: nil) }).disposed(by: disposeBag) diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift index 1402092..56a14c0 100644 --- a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift @@ -6,11 +6,132 @@ // import UIKit +import PinLayout +import FlexLayout +import Then +import ReactorKit -final class LiarGameSubjectViewController: UIViewController{ +final class LiarGameSubjectViewController: UIViewController, View{ + + init(reactor: LiarGameSubjectReactor){ + + super.init(nibName: nil, bundle: nil) + self.reactor = reactor + self.view.addSubview(flexLayoutContainer) + + self.flexLayoutContainer.flex.direction(.row).justifyContent(.center).alignItems(.stretch).wrap(.wrap).define{ flex in + flex.addItem(self.animalButton).width(100).height(25).marginTop(100).margin(10) + flex.addItem(self.exerciseButton).width(100).height(25).marginTop(100).margin(10) + flex.addItem(self.foodButton).width(100).height(25).marginTop(100).margin(10) + flex.addItem(self.electronicEquipmentButton).width(100).height(25).marginTop(10).margin(10) + flex.addItem(self.jobButton).width(100).height(25).marginTop(10).margin(10) + } + } + + @available(*, unavailable) + required init?(coder: NSCoder) { fatalError() } + + override func viewDidLayoutSubviews() { + self.flexLayoutContainer.pin.all() + self.flexLayoutContainer.flex.layout() + } + override func viewDidLoad() { self.view.backgroundColor = .green + self.setupView() + } + + let flexLayoutContainer: UIView = UIView() + + + var disposeBag: DisposeBag = DisposeBag() + + let animalButton: UIButton = UIButton() + let exerciseButton: UIButton = UIButton() + let foodButton: UIButton = UIButton() + let electronicEquipmentButton: UIButton = UIButton() + let jobButton: UIButton = UIButton() + + +} +extension LiarGameSubjectViewController{ + + func setupView(){ + animalButton.do{ + self.view.addSubview($0) + $0.backgroundColor = .yellow + $0.setTitle("동물", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + exerciseButton.do{ + self.view.addSubview($0) + $0.backgroundColor = .yellow + $0.setTitle("운동", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + foodButton.do{ + self.view.addSubview($0) + $0.backgroundColor = .yellow + $0.setTitle("음식", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + electronicEquipmentButton.do{ + self.view.addSubview($0) + $0.backgroundColor = .yellow + $0.setTitle("전자기기", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + jobButton.do{ + self.view.addSubview($0) + $0.backgroundColor = .yellow + $0.setTitle("직업", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + } + + +} +extension LiarGameSubjectViewController{ + + func bind(reactor: LiarGameSubjectReactor) { + animalButton.rx.tap.asDriver() + .drive(onNext:{ + reactor.action.onNext(.selectSubject(.animal)) + }).disposed(by: disposeBag) + + exerciseButton.rx.tap.asDriver() + .drive(onNext:{ + reactor.action.onNext(.selectSubject(.exercise)) + }).disposed(by: disposeBag) + + foodButton.rx.tap.asDriver() + .drive(onNext:{ + reactor.action.onNext(.selectSubject(.food)) + }).disposed(by: disposeBag) + + electronicEquipmentButton.rx.tap.asDriver() + .drive(onNext:{ + reactor.action.onNext(.selectSubject(.electronicEquipment)) + }).disposed(by: disposeBag) + + jobButton.rx.tap.asDriver() + .drive(onNext:{ + reactor.action.onNext(.selectSubject(.job)) + }).disposed(by: disposeBag) + + reactor.state.map{ $0.selectedSubject } + .withUnretained(self) + .subscribe(onNext:{ `self`, subject in + let liarGameVC = LiarGameViewController(subject: subject ?? .job) + liarGameVC.modalPresentationStyle = .fullScreen + self.present(liarGameVC, animated: true, completion: nil) + + }).disposed(by: disposeBag) + + } + + } diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift new file mode 100644 index 0000000..b8e73a0 --- /dev/null +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift @@ -0,0 +1,80 @@ +// +// LiarGameViewController.swift +// LiarGame +// +// Created by Jay on 2022/04/26. +// + +import UIKit +import Then +import RxSwift +import RxCocoa +import ReactorKit +import PinLayout +import FlexLayout + +final class LiarGameViewController: UIViewController{ + + init(subject: LiarGameSubject){ + self.selectSubject = subject + super.init(nibName: nil, bundle: nil) + flexContainer.flex.define{ flex in + flex.addItem(self.curtainView) + + } + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLayoutSubviews() { + self.flexContainer.pin.all() + self.flexContainer.flex.layout() + } + override func viewDidLoad() { + self.view.backgroundColor = .yellow + self.setupView() + } + + let flexContainer: UIView = UIView() + + var selectSubject: LiarGameSubject + // 가림막 만들기 가림막은 클릭 시 확인창이 뜸 + let curtainView: UIView = UIView() + let curtainLabel: UILabel = UILabel() + let curtainButton: UIButton = UIButton() + + // 단어 나타나기 화면 만들기 + let liarView: UIView = UIView() + let liarLabel: UILabel = UILabel() + let liarButton: UIButton = UIButton() + + // 게임 시작!!! + let endView: UIView = UIView() + let endLabel: UILabel = UILabel() + let endButton: UIButton = UIButton() + + +} +extension LiarGameViewController{ + + private func setupView(){ + self.view.addSubview(flexContainer) + + curtainView.do{ + self.view.addSubview($0) + $0.backgroundColor = .yellow + } + + curtainLabel.do{ + self.curtainView.addSubview($0) + $0.backgroundColor = .green + $0.text = "터치해서 가림막을 제거해주세요" + } + curtainButton.do{ + self.curtainView.addSubview($0) + } + } +} diff --git a/xcconfig/LiarGame-Shared.xcconfig b/xcconfig/LiarGame-Shared.xcconfig index 9756fe5..022fe36 100644 --- a/xcconfig/LiarGame-Shared.xcconfig +++ b/xcconfig/LiarGame-Shared.xcconfig @@ -181,4 +181,4 @@ SWIFT_VERSION = 5.0 TARGETED_DEVICE_FAMILY = 1,2 -#include "Secret.xcconfig" \ No newline at end of file +#include "Secret.xcconfig" From 63224797f6a770a8baae1b31dad7c623078085c9 Mon Sep 17 00:00:00 2001 From: LeeJaeWook <2jae66@gmail.com> Date: Tue, 26 Apr 2022 11:57:55 +0900 Subject: [PATCH 2/4] =?UTF-8?q?private=20=EC=A0=91=EA=B7=BC=20=EC=A0=9C?= =?UTF-8?q?=EC=96=B4=EC=9E=90=20=EC=B6=94=EA=B0=80=20&=20state=20nil=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=EB=A1=9C=20compactMap,=20distintuntilchange?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20flex=20Container=20addsubview=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewController/HomeViewController.swift | 4 ++-- .../LiarGameSubjectViewController.swift | 14 ++++++----- .../LiarGame/LiarGameViewController.swift | 24 +++++++++---------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/LiarGame/Sources/ViewController/HomeViewController.swift b/LiarGame/Sources/ViewController/HomeViewController.swift index 68d385e..7db82ae 100644 --- a/LiarGame/Sources/ViewController/HomeViewController.swift +++ b/LiarGame/Sources/ViewController/HomeViewController.swift @@ -45,10 +45,10 @@ final class HomeViewController: UIViewController, View{ self.setupView() } - let flexLayoutContainer: UIView = UIView() + private let flexLayoutContainer: UIView = UIView() var disposeBag: DisposeBag = DisposeBag() - let liarGameStartButton = UIButton() + private let liarGameStartButton = UIButton() } diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift index 56a14c0..0e6f7cc 100644 --- a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift @@ -43,16 +43,16 @@ final class LiarGameSubjectViewController: UIViewController, View{ self.setupView() } - let flexLayoutContainer: UIView = UIView() + private let flexLayoutContainer: UIView = UIView() var disposeBag: DisposeBag = DisposeBag() - let animalButton: UIButton = UIButton() - let exerciseButton: UIButton = UIButton() - let foodButton: UIButton = UIButton() - let electronicEquipmentButton: UIButton = UIButton() - let jobButton: UIButton = UIButton() + private let animalButton: UIButton = UIButton() + private let exerciseButton: UIButton = UIButton() + private let foodButton: UIButton = UIButton() + private let electronicEquipmentButton: UIButton = UIButton() + private let jobButton: UIButton = UIButton() } @@ -123,6 +123,8 @@ extension LiarGameSubjectViewController{ }).disposed(by: disposeBag) reactor.state.map{ $0.selectedSubject } + .compactMap{ $0 } + .distinctUntilChanged() .withUnretained(self) .subscribe(onNext:{ `self`, subject in let liarGameVC = LiarGameViewController(subject: subject ?? .job) diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift index b8e73a0..4897d2b 100644 --- a/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift @@ -38,30 +38,30 @@ final class LiarGameViewController: UIViewController{ self.setupView() } - let flexContainer: UIView = UIView() + private let flexContainer: UIView = UIView() - var selectSubject: LiarGameSubject + private var selectSubject: LiarGameSubject // 가림막 만들기 가림막은 클릭 시 확인창이 뜸 - let curtainView: UIView = UIView() - let curtainLabel: UILabel = UILabel() - let curtainButton: UIButton = UIButton() + private let curtainView: UIView = UIView() + private let curtainLabel: UILabel = UILabel() + private let curtainButton: UIButton = UIButton() // 단어 나타나기 화면 만들기 - let liarView: UIView = UIView() - let liarLabel: UILabel = UILabel() - let liarButton: UIButton = UIButton() + private let liarView: UIView = UIView() + private let liarLabel: UILabel = UILabel() + private let liarButton: UIButton = UIButton() // 게임 시작!!! - let endView: UIView = UIView() - let endLabel: UILabel = UILabel() - let endButton: UIButton = UIButton() + private let endView: UIView = UIView() + private let endLabel: UILabel = UILabel() + private let endButton: UIButton = UIButton() } extension LiarGameViewController{ private func setupView(){ - self.view.addSubview(flexContainer) +// self.view.addSubview(flexContainer) curtainView.do{ self.view.addSubview($0) From d52902ebc7f57a5f209d0bb020e469716825e41f Mon Sep 17 00:00:00 2001 From: LeeJaeWook <2jae66@gmail.com> Date: Tue, 26 Apr 2022 12:16:14 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=EB=B6=88=ED=95=84=EC=9A=94=ED=95=98?= =?UTF-8?q?=EA=B2=8C=20=EC=82=AC=EC=9A=A9=EB=90=9C=20asDriver=20subscribe?= =?UTF-8?q?=EB=A1=9C=20=EA=B5=90=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewController/HomeViewController.swift | 5 ++--- .../LiarGameSubjectViewController.swift | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/LiarGame/Sources/ViewController/HomeViewController.swift b/LiarGame/Sources/ViewController/HomeViewController.swift index 7db82ae..bc5d2a1 100644 --- a/LiarGame/Sources/ViewController/HomeViewController.swift +++ b/LiarGame/Sources/ViewController/HomeViewController.swift @@ -67,15 +67,14 @@ extension HomeViewController{ // MARK: - Binding extension HomeViewController{ func bind(reactor: Reactor) { - self.liarGameStartButton.rx.tap.asDriver() - .drive(onNext: { + self.liarGameStartButton.rx.tap + .subscribe(onNext:{ reactor.action.onNext(.updateMode("LIAR")) }).disposed(by: disposeBag) reactor.state.map { $0.mode } .subscribe(onNext: { - print($0) if $0 == "LIAR"{ let liarVC = LiarGameModeViewController(reactor: LiarGameModeReactor()) liarVC.modalPresentationStyle = .fullScreen diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift index 0e6f7cc..3889285 100644 --- a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift @@ -97,23 +97,24 @@ extension LiarGameSubjectViewController{ extension LiarGameSubjectViewController{ func bind(reactor: LiarGameSubjectReactor) { - animalButton.rx.tap.asDriver() - .drive(onNext:{ + animalButton.rx.tap + .subscribe(onNext:{ reactor.action.onNext(.selectSubject(.animal)) }).disposed(by: disposeBag) - - exerciseButton.rx.tap.asDriver() - .drive(onNext:{ + + exerciseButton.rx.tap + .subscribe(onNext:{ reactor.action.onNext(.selectSubject(.exercise)) }).disposed(by: disposeBag) + - foodButton.rx.tap.asDriver() - .drive(onNext:{ + foodButton.rx.tap + .subscribe(onNext:{ reactor.action.onNext(.selectSubject(.food)) }).disposed(by: disposeBag) - - electronicEquipmentButton.rx.tap.asDriver() - .drive(onNext:{ + + electronicEquipmentButton.rx.tap + .subscribe(onNext:{ reactor.action.onNext(.selectSubject(.electronicEquipment)) }).disposed(by: disposeBag) From 7d72cfedfc218017e8e4116190769595bbd5a6de Mon Sep 17 00:00:00 2001 From: LeeJaeWook <2jae66@gmail.com> Date: Tue, 26 Apr 2022 18:36:28 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=3F=3F=20job=20=EC=A0=9C=EA=B1=B0=20&=20add?= =?UTF-8?q?SubView=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LiarGame/LiarGameSubjectViewController.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift index 3889285..37f01b5 100644 --- a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift @@ -60,31 +60,26 @@ extension LiarGameSubjectViewController{ func setupView(){ animalButton.do{ - self.view.addSubview($0) $0.backgroundColor = .yellow $0.setTitle("동물", for: .normal) $0.setTitleColor(.black, for: .normal) } exerciseButton.do{ - self.view.addSubview($0) $0.backgroundColor = .yellow $0.setTitle("운동", for: .normal) $0.setTitleColor(.black, for: .normal) } foodButton.do{ - self.view.addSubview($0) $0.backgroundColor = .yellow $0.setTitle("음식", for: .normal) $0.setTitleColor(.black, for: .normal) } electronicEquipmentButton.do{ - self.view.addSubview($0) $0.backgroundColor = .yellow $0.setTitle("전자기기", for: .normal) $0.setTitleColor(.black, for: .normal) } jobButton.do{ - self.view.addSubview($0) $0.backgroundColor = .yellow $0.setTitle("직업", for: .normal) $0.setTitleColor(.black, for: .normal) @@ -128,7 +123,7 @@ extension LiarGameSubjectViewController{ .distinctUntilChanged() .withUnretained(self) .subscribe(onNext:{ `self`, subject in - let liarGameVC = LiarGameViewController(subject: subject ?? .job) + let liarGameVC = LiarGameViewController(subject: subject) liarGameVC.modalPresentationStyle = .fullScreen self.present(liarGameVC, animated: true, completion: nil)