forked from Ushien/Hackaton2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscussion.js
170 lines (149 loc) · 5.22 KB
/
discussion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
Ici on code la logique de discussion, en alternant les dialogs et les choices
*/
let discutionPatterns = [
["Salutations", "Premier_contact", "Check-up", "Entree_souvenir", "Transition", "Histoire_commune", "Au_revoir", "Easter_egg"],
//["Salutations", "Salutations"], ["Salutations","Premier_contact","Transition",]
//["Salutations", "Salutations", "Salutations"]
]
let currentDiscutionIndex = 0;
let currentDiscution = pickInList(discutionPatterns);
let currentDialogSuiteIndex = 0;
let currentDialogSuite = generateDialogSuiteFromName(currentDiscution[currentDiscutionIndex]);
// Say first dialog
buddySay(Object.values(currentDialogSuite[currentDialogSuiteIndex])[0])
function displayEmotion(id) {
if (dialogEmotions["question"].includes(id)) {
displayBuddy("question");
}
else if (dialogEmotions["content"].includes(id)) {
displayBuddy("content");
}
else if (dialogEmotions["wink"].includes(id)) {
displayBuddy("wink");
}
else {
displayBuddy("neutral");
}
}
function nextDialog() {
if (getDialogType(currentDialogSuite[Math.max(currentDialogSuiteIndex, 0)]) == "c") {
// On n'avance pas tant que l'utilisateur fait pas de choix
return;
}
// Goes to the next dialog
currentDialogSuiteIndex++;
if (currentDialogSuiteIndex >= currentDialogSuite.length) {
// On a fini la dialogSuite
if (currentDiscutionIndex < currentDiscution.length - 1) {
// Il y a encore d'autres dialogSuites à voir
currentDiscutionIndex++;
currentDialogSuiteIndex = -1;
currentDialogSuite = generateDialogSuiteFromName(currentDiscution[currentDiscutionIndex]);
nextDialog();
}
else {
// Plus rien à dire
$("#dialogBox").hide();
displayBuddy("sleep");
return;
}
}
else {
// On a pas fini la dialogSuite
let dialogType = getDialogType(currentDialogSuite[currentDialogSuiteIndex]);
switch (dialogType) {
case "d":
buddySay(Object.values(currentDialogSuite[currentDialogSuiteIndex])[0]);
displayEmotion(Object.keys(currentDialogSuite[currentDialogSuiteIndex])[0]);
break;
case "c":
let choiceID = Object.keys(currentDialogSuite[currentDialogSuiteIndex])[0];
displayChoice(getChoice(choiceID));
break;
case "m":
Object.values(currentDialogSuite[currentDialogSuiteIndex])[0]();
break;
case "e":
Object.values(currentDialogSuite[currentDialogSuiteIndex])[0]();
nextDialog();
break;
}
}
}
function madeChoice(nb) {
/* The user chose option n° nb */
let choiceID = Object.keys(currentDialogSuite[currentDialogSuiteIndex])[0];
currentDialogSuite = generateDialogSuiteFromDialogList(currentDialogSuite[currentDialogSuiteIndex][choiceID][nb]);
currentDialogSuiteIndex = -1;
nextDialog();
hideChoices();
}
function getDialogType(dialog) {
return Object.keys(dialog)[0][0];
}
/*
Vous lui donnez un discussionTheme ("Salutations", "Au revoir")
Il vous renvoie la chaîne de discussions par rapport à ces critères.
*/
function generateDialogSuiteFromName(dialogSuiteName){
/*
Reçoit un nom de dialogSuite de dialog.js
Le converti en une suite de dialogues (choisit la version exacte de chaque dialogue)
Ex: [{"d001": "Bonjour!"}, {"d002": "Comment ça va ?"}, {"c001": {1: [...], 2: [...]}}]
*/
let possibleDialogs = dialogSuites[dialogSuiteName];
let discussion = [];
for (let dialogID of possibleDialogs) {
let chosenDialog = dialogID;
if (dialogID[0] == "d") {
chosenDialog = {};
chosenDialog[dialogID] = pickInList(getDialog(dialogID));
}
else if (dialogID[0] == "m") {
chosenDialog = {};
chosenDialog[dialogID] = modals[dialogID];
}
else if (dialogID[0] == "e") {
chosenDialog = {};
chosenDialog[dialogID] = events[dialogID];
}
discussion.push(chosenDialog);
}
return discussion;
}
function generateDialogSuiteFromDialogList(list) {
/*
Reçoit une liste d'ID de dialogues, choices, ...
Le converti en une suite de dialogues (choisit la version exacte de chaque dialogue)
Ex: [{"d001": "Bonjour!"}, {"d002": "Comment ça va ?"}, {"c001": {1: [...], 2: [...]}}]
*/
let discussion = [];
for (let dialogID of list) {
let chosenDialog = dialogID;
if (dialogID[0] == "d") {
chosenDialog = {};
chosenDialog[dialogID] = pickInList(getDialog(dialogID));
}
else if (dialogID[0] == "m") {
chosenDialog = {};
chosenDialog[dialogID] = modals[dialogID];
}
else if (dialogID[0] == "e") {
chosenDialog = {};
chosenDialog[dialogID] = events[dialogID];
}
discussion.push(chosenDialog);
}
return discussion;
}
$("body").click(() => {
if (modalDisplayed) {
return;
}
if (talking) {
speedDialog();
return;
}
nextDialog();
});