Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game: Create a new quiz feature #2919

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open

Game: Create a new quiz feature #2919

wants to merge 82 commits into from

Conversation

CYX22222003
Copy link

@CYX22222003 CYX22222003 commented Apr 9, 2024

Description

Previously, the quiz feature of the game was implemented by jumping between dialogue segments based on the player's choices. We have now separated the quiz component from the dialogue objects and achieved the following improvements:

  • Display scores and store quiz results
  • Create branching storylines based on different quiz results
  • Simplify story writing syntax for quiz components

GameQuizManager

Renders the quiz using dialogue boxes and prompts UI. A prompt for players to choose whether they want to start the quiz is added before every quiz starts.

QuizParser

Parses the quiz content under the quizzes header in the story file.

Saving quiz results

Quiz results are saved as an array of [string, number] pairs, representing the quizId and the latest score of the corresponding quiz. The score of a quiz is the number of questions answered correctly.

New actions & conditions

Adds new action show_quiz to show a quiz. The show_quiz action is recommended to only be used in dialogues. During a quiz, the dialogue box and speaker belonging to the dialogue will be set invisible, and keyboard inputs will be disabled.

New conditions attemptedQuiz, passedQuiz, and quizScore are added for story writers to check the completion status of a quiz. attemptedQuiz is true if the player has played all questions in the given quiz, regardless of the scores obtained. passedQuiz is true if the player has played all questions in the given quiz and got full marks. quizScore is true if the score of the given quiz is greater than or equal to the given number.
The syntax for conditions in txt file is as follows:

attemptedQuiz.<quizId>
passedQuiz.<quizId>
quizScore.<quizId>.<number>

Interpolation of quiz scores in dialogues

Storywriters can insert quiz scores in dialogue lines. This allows writers to define how they want to show the quiz score. The syntax in txt file is similar to inserting the player's name in dialogues:

@scottie, normal, left
You got {<quizId>.score} questions right!

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code quality improvements

How to test

As this feature should be backward compatible, all previous mock chapters on Source Academy & all chapters already uploaded on Source Academy should function without issues.
A mock chapter containing quizzes is used to test the new features in the game simulator.

Checklist

  • I have tested this code
  • I have updated the documentation

@coveralls
Copy link

coveralls commented Apr 9, 2024

Pull Request Test Coverage Report for Build 9114802444

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 31.41%

Totals Coverage Status
Change from base Build 9101202777: 0.0%
Covered Lines: 4891
Relevant Lines: 14671

💛 - Coveralls

reginateh and others added 27 commits April 10, 2024 17:18
…fault (#2848)

* Make compact components the new default and remove any mentions to the old components.
Also removes the experimental button toggle.

* Update test snapshots

* Clean up testing code a little

* Formatting changes

* Fix some minor issues
* bumping js-slang

* Update tests

* remove obsolete snapshots

---------

Co-authored-by: NhatMinh0208 <minhkhicon2468@gmail.com>
Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for the late review, thanks wo I did a quick look through the code and have some rough feedback below.

P.S.: Could you provide a screenshot of what the new feature looks like?

src/features/game/save/GameSaveTypes.ts Outdated Show resolved Hide resolved
src/features/game/state/GameStateManager.ts Outdated Show resolved Hide resolved
src/features/game/state/GameStateManager.ts Show resolved Hide resolved
src/features/game/state/GameStateManager.ts Outdated Show resolved Hide resolved
src/features/game/state/GameStateManager.ts Show resolved Hide resolved
src/features/game/state/GameStateManager.ts Show resolved Hide resolved
src/features/game/dialogue/GameDialogueManager.ts Outdated Show resolved Hide resolved
src/features/game/dialogue/GameDialogueManager.ts Outdated Show resolved Hide resolved
CYX22222003 and others added 5 commits May 12, 2024 20:32
Modify getDialogueRenderer method access modifier
correct documentation errors
Remove the unnecessary use of parameterized type
simplify unnecessary conditional statement

Co-authored-by: Richard Dominick <34370238+RichDom2185@users.noreply.github.com>
@CYX22222003
Copy link
Author

Hi, sorry for the late review, thanks wo I did a quick look through the code and have some rough feedback below.

P.S.: Could you provide a screenshot of what the new feature looks like?

quiz question and options:
Screenshot 2024-04-05 114801

quiz starting prompt
Screenshot 2024-04-09 185338

character reaction to students' response
Screenshot 2024-04-09 185505

Copy link
Collaborator

@lhw-1 lhw-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @CYX22222003 @reginateh - your work over the semester is much appreciated! This feature should be quite helpful for game storywriters moving forward 😄

Apart from the images (which I see you've posted), could you also provide a full example of a quiz being written in a checkpoint txt file? It would be helpful as a cross-reference.

Also, after this PR, please don't forget to update the documentation for the game developer guide & the storywriter guide!

Here are some small queries / nits to address:

Comment on lines +106 to +108
globalAPI.enableKeyboardInput(false);
await globalAPI.showQuiz(actionParams.id);
globalAPI.enableKeyboardInput(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remind me on why disabling and then enabling keyboard input is necessary here?

(I do remember discussing this in person but can't seem to remember why at the moment & will be better to have it documented within the PR as well)

Copy link
Author

@CYX22222003 CYX22222003 May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is to prevent the trigger of dialogue line proceeding while attempting the quiz.

@@ -79,6 +80,7 @@ export default class DialogueManager {

// Disable interactions while processing actions
GameGlobalAPI.getInstance().enableSprite(this.getDialogueRenderer().getDialogueBox(), false);
this.getInputManager().enableKeyboardInput(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling and then enabling keyboard input was already done in GameActionExecuter.ts - are the rationale different for these two cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the enabling and disabling input in GameActionExecutor is because we currently disable any keyboard inputs while attempting the quiz to prevent its interference with the normal proceeding of dialogue.

src/features/game/dialogue/GameDialogueRenderer.ts Outdated Show resolved Hide resolved
src/features/game/dialogue/GameDialogueSpeakerRenderer.ts Outdated Show resolved Hide resolved
src/features/game/quiz/GameQuizManager.ts Outdated Show resolved Hide resolved
header,
quizQuestionBox,
quizQuestionWriter.container
]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that there is quite a bit of rendering-related code here, I'm wondering if a refactor would be a possibility - any thoughts?

(It's fine if it's non-trivial, given the complex inter-weaving between dialogue and quizzes - a bigger refactor might be necessary later on, which would be out of scope for this PR. But if possible, we should prevent it from snowballing early on)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be possible that we can create a method for generating all the UI components and return them as an array. Any other thoughts @reginateh

src/features/game/quiz/GameQuizManager.ts Outdated Show resolved Hide resolved
src/features/game/quiz/GameQuizManager.ts Outdated Show resolved Hide resolved
src/features/game/scenes/gameManager/GameGlobalAPI.ts Outdated Show resolved Hide resolved
CYX22222003 and others added 8 commits May 16, 2024 11:49
refactor the logic of makeLineQuizScores method

Co-authored-by: reginateh <154109919+reginateh@users.noreply.github.com>
remove unnecessary comment line
change method access modifiers
change method access modifiers
reformatting

Co-authored-by: Lee Hyung Woon / 이형운 <leehyungwoonsamuel@gmail.com>
change variable name
change the parameters of game components setting
@CYX22222003
Copy link
Author

Thanks for the PR @CYX22222003 @reginateh - your work over the semester is much appreciated! This feature should be quite helpful for game storywriters moving forward 😄

Apart from the images (which I see you've posted), could you also provide a full example of a quiz being written in a checkpoint txt file? It would be helpful as a cross-reference.

Also, after this PR, please don't forget to update the documentation for the game developer guide & the storywriter guide!

Here are some small queries / nits to address:

Here is a sample of quiz:

quizzes
    sourceManual
        0
        What is the pre-declared constant for: The Number value for π, the ratio of the circumference of a circle to its diameter?
        answer: 3
        option
            apple_Pi
            @ershk, thinking, left
            ...Are you hungry or something?
        option
            math_Pi
        option
            math_pi
        option
            math_PI

        1
        What is the pre-declared constant for: The Number value for the base-10 logarithm of e, the base of the natural logarithms?
        answer: 2
        option
            math_L10
        option
            math_LOG10
        option
            math_LOG10E
        option
            math_L10E

    telebayConsole
        0
        The first expression is: 100 + 37; What is the simplified form for this expression?
        answer: 3
        option
            13
        option
            37
        option
            100
        option
            137
            @scottie, smile, left
            Great! Looks like that worked.

        1
        The second expression is: (6 + 8) * 7 + 2 * 3; What is the simplified form for this expression?
        answer: 1
        option
            103
        option
            104
            @scottie, smile, left
            Great! Looks like that worked, too.
        option
            300
        option
            378

Use the showQuiz method inside a dialogue

 2
        @ershk, excited, left
        Yeah. Let's do this!
        @ershk, happy, left
        You can refer to the Source documentation if you'd like! Maybe that will help us get used to it, too.
        @ershk, normal, left
        Let's get started!
            show_quiz*(sourceManual)
        @ershk, normal, left

@CYX22222003
Copy link
Author

Thanks for the PR @CYX22222003 @reginateh - your work over the semester is much appreciated! This feature should be quite helpful for game storywriters moving forward 😄

Apart from the images (which I see you've posted), could you also provide a full example of a quiz being written in a checkpoint txt file? It would be helpful as a cross-reference.

Also, after this PR, please don't forget to update the documentation for the game developer guide & the storywriter guide!

Here are some small queries / nits to address:

We have updated the game developer guide but we cannot push our changes of the storywriter guide to the general repo.

guest1@CHENYIXUN and others added 3 commits May 16, 2024 22:59
Correct parsers' behavior for errors

Co-authored-by: Lee Hyung Woon / 이형운 <leehyungwoonsamuel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants