| 1 | #include "System/SphinxQuizData.h" |
|---|---|
| 2 | |
| 3 | #include "Library/Yaml/ByamlIter.h" |
| 4 | #include "Library/Yaml/Writer/ByamlWriter.h" |
| 5 | |
| 6 | SphinxQuizData::SphinxQuizData(s32 arraySize) : mArraySize(arraySize) { |
| 7 | mIsAnswerCorrectSphinxQuiz = new bool[mArraySize]; |
| 8 | mIsAnswerCorrectSphinxQuizAll = new bool[mArraySize]; |
| 9 | |
| 10 | init(); |
| 11 | } |
| 12 | |
| 13 | void SphinxQuizData::init() { |
| 14 | for (s32 i = 0; i < mArraySize; i++) { |
| 15 | mIsAnswerCorrectSphinxQuiz[i] = false; |
| 16 | mIsAnswerCorrectSphinxQuizAll[i] = false; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | void SphinxQuizData::answerCorrectSphinxQuiz(s32 index) { |
| 21 | mIsAnswerCorrectSphinxQuiz[index] = true; |
| 22 | } |
| 23 | |
| 24 | void SphinxQuizData::answerCorrectSphinxQuizAll(s32 index) { |
| 25 | mIsAnswerCorrectSphinxQuizAll[index] = true; |
| 26 | } |
| 27 | |
| 28 | bool SphinxQuizData::isAnswerCorrectSphinxQuiz(s32 index) const { |
| 29 | return mIsAnswerCorrectSphinxQuiz[index]; |
| 30 | } |
| 31 | |
| 32 | bool SphinxQuizData::isAnswerCorrectSphinxQuizAll(s32 index) const { |
| 33 | return mIsAnswerCorrectSphinxQuizAll[index]; |
| 34 | } |
| 35 | |
| 36 | void SphinxQuizData::write(al::ByamlWriter* writer) { |
| 37 | for (s32 i = 0; i < mArraySize; i++) { |
| 38 | writer->pushHash(); |
| 39 | writer->addBool("IsAnswerCorrectSphinxQuiz", mIsAnswerCorrectSphinxQuiz[i]); |
| 40 | writer->addBool("IsAnswerCorrectSphinxQuizAll", mIsAnswerCorrectSphinxQuizAll[i]); |
| 41 | writer->pop(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void SphinxQuizData::read(const al::ByamlIter& reader) { |
| 46 | init(); |
| 47 | |
| 48 | for (s32 i = 0; i < mArraySize; i++) { |
| 49 | al::ByamlIter sphinxData{}; |
| 50 | reader.tryGetIterByIndex(iter: &sphinxData, index: i); |
| 51 | sphinxData.tryGetBoolByKey(val: &mIsAnswerCorrectSphinxQuiz[i], key: "IsAnswerCorrectSphinxQuiz"); |
| 52 | sphinxData.tryGetBoolByKey(val: &mIsAnswerCorrectSphinxQuizAll[i], |
| 53 | key: "IsAnswerCorrectSphinxQuizAll"); |
| 54 | } |
| 55 | } |
| 56 |