Skip to content

Commit 9758022

Browse files
reginatehguest1@CHENYIXUN
authored andcommitted
reformat
1 parent 2ecf439 commit 9758022

File tree

8 files changed

+52
-43
lines changed

8 files changed

+52
-43
lines changed

src/features/game/location/GameMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { AssetKey, ItemId } from '../commons/CommonTypes';
66
import { Dialogue } from '../dialogue/GameDialogueTypes';
77
import { GameMode } from '../mode/GameModeTypes';
88
import { ObjectProperty } from '../objects/GameObjectTypes';
9+
import { Quiz } from '../quiz/GameQuizType';
910
import { mandatory } from '../utils/GameUtils';
1011
import { AnyId, GameItemType, GameLocation, LocationId } from './GameMapTypes';
11-
import { Quiz } from '../quiz/GameQuizType';
1212

1313
/**
1414
* Game map is the class that encapsulates data about

src/features/game/parser/Parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import DialoguesParser from './DialogueParser';
88
import LocationsParser from './LocationDetailsParser';
99
import LocationParser from './LocationParser';
1010
import ParserValidator, { GameEntityType } from './ParserValidator';
11-
import TasksParser from './TasksParser';
1211
import QuizParser from './QuizParser';
12+
import TasksParser from './TasksParser';
1313

1414
/**
1515
* This class converts a checkpoint txt file into a Checkpoint

src/features/game/parser/QuizParser.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Parser from "./Parser";
2-
import StringUtils from "../utils/StringUtils";
3-
import { Quiz, Question, Option } from "../quiz/GameQuizType";
4-
import DialogueParser from "./DialogueParser";
5-
import { DialogueObject } from "../dialogue/GameDialogueTypes";
1+
import { DialogueObject } from '../dialogue/GameDialogueTypes';
62
import { GameItemType } from '../location/GameMapTypes';
7-
import { defaultReaction } from "../quiz/GameQuizConstants";
3+
import { defaultReaction } from '../quiz/GameQuizConstants';
4+
import { Option, Question, Quiz } from '../quiz/GameQuizType';
5+
import StringUtils from '../utils/StringUtils';
6+
import DialogueParser from './DialogueParser';
7+
import Parser from './Parser';
88

99
/**
1010
* This class parses quizzes and creates Quiz Objects
@@ -15,7 +15,7 @@ export default class QuizParser {
1515
* This function reads the entire text under the "quizzes" heading,
1616
* converts quizzes listed underneath into Quiz entities,
1717
* and stores these quizzes in the game map.
18-
*
18+
*
1919
* @param quizText the entire quiz text beneath quizzes heading
2020
*/
2121
public static parse(quizText: string[]) {
@@ -26,20 +26,20 @@ export default class QuizParser {
2626
return;
2727
}
2828
this.parseQuiz(quizId, quizBody);
29-
})
29+
});
3030
}
3131

3232
/**
3333
* This function parses one quiz and stores it into the game map.
34-
*
34+
*
3535
* @param quizId the string containing quiz Id
3636
* @param quizBody the body of the dialogue containing its questions and options
3737
*/
3838
private static parseQuiz(quizId: string, quizBody: string[]) {
3939
Parser.validator.registerId(quizId);
4040
const rawQuestions: Map<string, string[]> = StringUtils.mapByHeader(quizBody, isInteger);
4141
const questions: Question[] = this.parseQuizQuestions(rawQuestions);
42-
const quiz: Quiz = {questions: questions};
42+
const quiz: Quiz = { questions: questions };
4343
Parser.checkpoint.map.setItemInMap(GameItemType.quizzes, quizId, quiz);
4444
}
4545

@@ -90,35 +90,41 @@ export default class QuizParser {
9090
* This function parses options of a question and
9191
* store them in an array.
9292
*
93-
* @param optionsText An Array of string containing all options' content,
93+
* @param optionsText An Array of string containing all options' content,
9494
* including option text and reactions
9595
* @param answer The correct answer of the corresponding question
9696
*/
9797
private static parseOptions(optionsText: string[], answer: Number): Option[] {
9898
const optionsParagraph = StringUtils.splitToParagraph(optionsText);
9999
const options: Option[] = Array(optionsParagraph.length);
100100
optionsParagraph.forEach(([header, content]: [string, string[]], index) => {
101-
options[index] = this.createOption(content, (answer === index));
101+
options[index] = this.createOption(content, answer === index);
102102
});
103103
return options;
104104
}
105105

106106
/**
107107
* This function creates an Option object.
108108
*
109-
* @param content An Array of string containing an option's content,
109+
* @param content An Array of string containing an option's content,
110110
* including option text and reaction
111111
* @param isCorrect Indicates whether this option is the correct answer
112112
* @param [defaultReaction=false] Indicates whether this option uses the default reaction
113113
*/
114-
private static createOption(content: string[], isCorrect: boolean, defaultReaction: boolean = false): Option {
114+
private static createOption(
115+
content: string[],
116+
isCorrect: boolean,
117+
defaultReaction: boolean = false
118+
): Option {
115119
if (content.length <= 1) {
116120
defaultReaction = true;
117121
}
118122
const option: Option = {
119123
text: content[0],
120-
reaction: defaultReaction ? this.createDefaultReaction(isCorrect) : DialogueParser.parseQuizReaction(content.slice(1))
121-
}
124+
reaction: defaultReaction
125+
? this.createDefaultReaction(isCorrect)
126+
: DialogueParser.parseQuizReaction(content.slice(1))
127+
};
122128
return option;
123129
}
124130

@@ -137,4 +143,4 @@ export default class QuizParser {
137143
}
138144
}
139145

140-
const isInteger = (line: string) => new RegExp(/^[0-9]+$/).test(line);
146+
const isInteger = (line: string) => new RegExp(/^[0-9]+$/).test(line);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const defaultReaction = {
2-
correct: ["You are right."],
3-
wrong: ["Wrong answer..."]
4-
}
2+
correct: ['You are right.'],
3+
wrong: ['Wrong answer...']
4+
};
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
import GameGlobalAPI from "../scenes/gameManager/GameGlobalAPI";
2-
import { ItemId } from "../commons/CommonTypes";
3-
import { Question, Option } from "./GameQuizType";
4-
import { DialogueLine } from "../dialogue/GameDialogueTypes";
1+
import { ItemId } from '../commons/CommonTypes';
2+
import { DialogueLine } from '../dialogue/GameDialogueTypes';
3+
import GameGlobalAPI from '../scenes/gameManager/GameGlobalAPI';
4+
import { Option, Question } from './GameQuizType';
55

66
export default class QuizManager {
7-
87
// Print everything. To test if the quiz parser parses correctly.
98
public showQuiz(quizId: ItemId) {
10-
console.log("A quiz is shown");
9+
console.log('A quiz is shown');
1110
const quiz = GameGlobalAPI.getInstance().getQuizById(quizId); // get a quiz
1211
const questions = quiz.questions;
13-
questions.forEach((value: Question) => {this.showQuestion(value)});
12+
questions.forEach((value: Question) => {
13+
this.showQuestion(value);
14+
});
1415
}
1516

1617
private showQuestion(question: Question) {
1718
console.log(question.question);
1819
console.log(question.answer);
19-
question.options.forEach((option) => {this.showOption(option)});
20+
question.options.forEach(option => {
21+
this.showOption(option);
22+
});
2023
}
2124

2225
private showOption(option: Option) {
@@ -27,4 +30,4 @@ export default class QuizManager {
2730
private showReaction(reaction: DialogueLine[]) {
2831
reaction.forEach((line: DialogueLine) => console.log(line.line));
2932
}
30-
}
33+
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { DialogueObject } from "../dialogue/GameDialogueTypes";
1+
import { DialogueObject } from '../dialogue/GameDialogueTypes';
22

33
export type Quiz = {
4-
questions: Question[]
5-
}
4+
questions: Question[];
5+
};
66

77
export type Question = {
8-
question: string,
9-
answer: Number,
10-
options: Option[]
11-
}
8+
question: string;
9+
answer: Number;
10+
options: Option[];
11+
};
1212

1313
export type Option = {
14-
text: string,
15-
reaction: DialogueObject
16-
}
14+
text: string;
15+
reaction: DialogueObject;
16+
};

src/features/game/scenes/gameManager/GameGlobalAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import { AnyId, GameItemType, GameLocation, LocationId } from '../../location/Ga
1414
import { GameMode } from '../../mode/GameModeTypes';
1515
import { ObjectProperty } from '../../objects/GameObjectTypes';
1616
import { GamePhaseType } from '../../phase/GamePhaseTypes';
17+
import { Quiz } from '../../quiz/GameQuizType';
1718
import { SettingsJson } from '../../save/GameSaveTypes';
1819
import SourceAcademyGame from '../../SourceAcademyGame';
1920
import { StateObserver, UserStateType } from '../../state/GameStateTypes';
2021
import { TaskDetail } from '../../task/GameTaskTypes';
2122
import { courseId, mandatory } from '../../utils/GameUtils';
2223
import GameManager from './GameManager';
23-
import { Quiz } from '../../quiz/GameQuizType';
2424

2525
/**
2626
* This class exposes all the public API's of managers

src/features/game/scenes/gameManager/GameManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import GameObjectManager from '../../objects/GameObjectManager';
2727
import GamePhaseManager from '../../phase/GamePhaseManager';
2828
import { GamePhaseType } from '../../phase/GamePhaseTypes';
2929
import GamePopUpManager from '../../popUp/GamePopUpManager';
30+
import GameQuizManager from '../../quiz/GameQuizManager';
3031
import SourceAcademyGame from '../../SourceAcademyGame';
3132
import GameStateManager from '../../state/GameStateManager';
3233
import GameTaskLogManager from '../../task/GameTaskLogManager';
3334
import GameToolbarManager from '../../toolbar/GameToolbarManager';
3435
import { mandatory, sleep, toS3Path } from '../../utils/GameUtils';
3536
import GameGlobalAPI from './GameGlobalAPI';
3637
import { createGamePhases } from './GameManagerHelper';
37-
import GameQuizManager from '../../quiz/GameQuizManager';
3838

3939
type GameManagerProps = {
4040
continueGame: boolean;

0 commit comments

Comments
 (0)