Cards shuffle correctly, remove statistics tabview

This commit is contained in:
Avery Pace
2021-11-11 10:04:48 -05:00
parent baa09e4363
commit 42ebdbf74a
5 changed files with 1737 additions and 15 deletions

View File

@@ -21,7 +21,7 @@ struct ContentView: View {
TabView {
TranslatorView()
.tabItem {
Image(systemName: "pencil")
Image(systemName: "message")
Text("Phrase Lookup")
}
FlashCardLessonsView()
@@ -29,11 +29,11 @@ struct ContentView: View {
Image(systemName: "character.textbox")
Text("Flash Cards")
}
FlashCardResultsView()
.tabItem {
Image(systemName: "number.circle")
Text("Flash Card Results")
}
// FlashCardResultsView()
// .tabItem {
// Image(systemName: "number.circle")
// Text("Flash Card Results")
// }
}
}

View File

@@ -67,7 +67,7 @@ struct FlashCardLessonsView: View {
var body: some View {
NavigationView {
List(flashCardLessonsVM.lessons, id: \.lesson) { lesson in
NavigationLink(destination: FlashCardView(lesson: lesson.lesson, passedDictionary: lesson.words)) {
NavigationLink(destination: FlashCardView(lesson: lesson.lesson, passedDictionary: lesson.words.shuffled())) {
Text(lesson.lesson)
.bold()
.onAppear {

View File

@@ -61,6 +61,7 @@ struct FlashCardStack: View {
var currentLesson: String
var dictionary: [TokiDictEntry]
@State private var shuffledDictionary: [TokiDictEntry] = []
@State private var flashCards: [FlashCard] = []
@State private var topFlashCard: FlashCard? = nil
@State private var flashCardsAreInteractive: [Bool] = []
@@ -71,6 +72,11 @@ struct FlashCardStack: View {
@State private var currentFlashCard = 0
init(currentLesson: String, dictionary: [TokiDictEntry]) {
self.currentLesson = currentLesson
self.dictionary = dictionary
}
var body: some View {
VStack {
ZStack {
@@ -99,10 +105,12 @@ struct FlashCardStack: View {
func initFlashCards() {
flashCards = []
for index in dictionary.indices {
shuffledDictionary = dictionary
shuffledDictionary.shuffle()
for index in shuffledDictionary.indices {
flashCardsAreInteractive.append(false)
flashCardsResults.append(FlashCardResult.Unanswered)
flashCards.append(FlashCard(isInteractive: $flashCardsAreInteractive[index], result: $flashCardsResults[index].onChange(cardAnswerReceived), dictionaryEntry: dictionary[index]))
flashCards.append(FlashCard(isInteractive: $flashCardsAreInteractive[index], result: $flashCardsResults[index].onChange(cardAnswerReceived), dictionaryEntry: shuffledDictionary[index]))
flashCardsVertOffset.append(370)
}
if flashCards.count - currentFlashCard >= 3 {
@@ -134,7 +142,7 @@ struct FlashCardStack: View {
func setFlashCardAnswersCoreData(_ correct: Bool) {
var cardInDatabase = false
for answer in flashCardAnswers {
if answer.word == dictionary[currentFlashCard].word {
if answer.word == shuffledDictionary[currentFlashCard].word {
print("word in database: \(answer.word)")
print("tries: \(answer.triesCount)")
print("correct`: \(answer.correctCount)")
@@ -171,7 +179,7 @@ struct FlashCardStack: View {
if cardInDatabase == false {
let answer = FlashCardAnswer(context: viewContext)
answer.word = dictionary[currentFlashCard].word
answer.word = shuffledDictionary[currentFlashCard].word
answer.triesCount = 1
if correct {
answer.correctCount = 1