-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheus.eliom
273 lines (242 loc) · 8.87 KB
/
eus.eliom
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
(**************************************************************************)
(* Copyright 2014, Ion Alberdi <nolaridebi at gmail.com> *)
(* *)
(* Licensed under the Apache License, Version 2.0 (the "License"); *)
(* you may not use this file except in compliance with the License. *)
(* You may obtain a copy of the License at *)
(* *)
(* http://www.apache.org/licenses/LICENSE-2.0 *)
(* *)
(* Unless required by applicable law or agreed to in writing, software *)
(* distributed under the License is distributed on an "AS IS" BASIS, *)
(* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *)
(* implied. See the License for the specific language governing *)
(* permissions and limitations under the License. *)
(**************************************************************************)
{client{
open Eliom_lib
open Eliom_content
open Tyxml_js
module RandomVerbs: sig
val random_nor_verb: unit -> string
val random_nor_nork_verb: unit -> string
val random_nor_nori_verb: unit -> string
end =
struct
let intransitive_verbs = ["izan"]
let transitive_verbs = ["ukan"; "ikusi"; "jan"]
let nor_nori_verbs = ["gustatu"]
let random_nor_verb () = Games.random_element intransitive_verbs
let random_nor_nork_verb () = Games.random_element transitive_verbs
let random_nor_nori_verb () = Games.random_element nor_nori_verbs
end
module IndicativePastPresentShared = struct
include Eus_aditzak.Questions
type t = {
v_mode: [ `Nor | `NorNork | `NorNori | `All ];
t_mode: [ `Past | `Present | `All ];
}
let description = "The first game consists at conjugating verbs"
let default_num_of_questions = 5
let supported_levels = [`Hard]
let other_number_of_questions = [1; 10; 25; 50; 100]
let correct_answer_message = "Oso ondo !"
let bad_answer_prefix = "Zuzenketa: "
type create_arg = unit
let v_mode_argument =
let open Games in
{argument_description = "In which mode would you like to conjugate the verbs?";
argument_label="mode";
non_default_arguments = ["nor"; "nor/nori"; "all" ];
default_argument = "nor/nork"}
let v_time_argument =
let open Games in
{argument_description = "In which time would you like to conjugate the verbs?";
argument_label="time";
non_default_arguments = ["past"; "all"];
default_argument = "present"
}
let arguments = Array.of_list [v_mode_argument; v_time_argument]
let modes = [`Nor; `NorNork; `NorNori]
let times = [`Past; `Present]
let nor_modes = [`Ni; `Hi; `Hura; `Gu; `Zu; `Zuek; `Haiek]
let nork_modes = [`Nik; (`Hik `Male); (`Hik `Female);
`Hark; `Guk; `Zuk; `Zuek; `Haiek]
let nori_modes = [`Niri; (`Hiri `Male); (`Hiri `Female);
`Hari; `Guri; `Zuri; `Zuei; `Haiei]
let nor_to_string x =
match x with
| `Ni -> "ni"
| `Hi -> "hi"
| `Hura -> "hura"
| `Gu -> "gu"
| `Zu -> "zu"
| `Zuek -> "zuek"
| `Haiek -> "haiek"
let nork_to_string x =
match x with
| `Nik -> "nik"
| `Hik p -> begin
match p with
| `Male -> "hik (male)"
| `Female -> "hik (female)"
end
| `Hark -> "hark"
| `Guk -> "guk"
| `Zuk -> "zuk"
| `Zuek -> "zuek"
| `Haiek -> "haiek"
let nori_to_string x =
match x with
| `Niri -> "niri"
| `Hiri p -> begin
match p with
| `Male -> "hiri (male)"
| `Female -> "hiri (female)"
end
| `Hari -> "hari"
| `Guri -> "guri"
| `Zuri -> "zuri"
| `Zuei -> "zuei"
| `Haiei -> "haiei"
let time_to_string x =
match x with
| `Present -> "present"
| `Past -> "past"
let v_mode_of_string v =
match v with
| "nor" -> `Nor
| "nor/nork" -> `NorNork
| "nor/nori" -> `NorNori
| "all" -> `All
| _ -> assert(false)
let t_mode_of_string v =
match v with
| "present" -> `Present
| "past" -> `Past
| "all" -> `All
| _ -> assert(false)
let create _ arg =
let v_mode, t_mode = arg.(0), arg.(1) in
{
v_mode = v_mode_of_string v_mode;
t_mode = t_mode_of_string t_mode;
}
let generate_question t =
let open Games in
let valid_modes =
match t.v_mode with
| `Nor -> [`Nor]
| `NorNork -> [`NorNork]
| `NorNori -> [`NorNori]
| `All -> modes
in
let valid_times =
match t.t_mode with
| `Present -> [`Present]
| `Past -> [`Past]
| `All -> times
in
let v_mode, time = random_element valid_modes, random_element valid_times in
match v_mode with
| `Nor -> (`Nor (random_element nor_modes), RandomVerbs.random_nor_verb (), time)
| `NorNork -> (`NorNork (random_element nor_modes,
random_element nork_modes),
RandomVerbs.random_nor_nork_verb (),
time)
| `NorNori ->
(`NorNori (random_element nor_modes, random_element nori_modes),
RandomVerbs.random_nor_nori_verb (),
time)
let question_to_string current_question answero =
let ps = Printf.sprintf in
let answer =
match answero with
| None -> "..."
| Some x -> x
in
match current_question with
| (`Nor nor, v, time) -> ps "%s %s %s (%s)" (nor_to_string nor) v answer (time_to_string time)
| (`NorNork (nor, nork), v, time) -> ps "%s %s %s %s (%s)" (nork_to_string nork) (nor_to_string nor) v answer (time_to_string time)
| (`NorNori (nor, nori), v, time) -> ps "%s %s %s %s (%s)" (nor_to_string nor) (nori_to_string nori) v answer (time_to_string time)
let question_answer current_question =
let mode, _, time = current_question in
Tables.conjugate mode time
let question_additional_answers _ _ = []
end
}}
{client{
module IndicativePastPresentClient = struct
include IndicativePastPresentShared
module E = Eus_aditzak
type supported_help = [`NorNorkPresent | `NorNoriPresent]
type help_t = (supported_help * E.animation) option
let stop_animation animo =
match animo with
| None -> ()
| Some (mode, t) ->
match mode with
| `NorNorkPresent -> E.NorNorkAnimation.stop_animation t
| `NorNoriPresent -> E.NorNoriAnimation.stop_animation t
let create_help_button refocus_after_click t f =
let play_help = Games.create_button `Info "Show me how it works" in
let help_dom = To_dom.of_button play_help in
let on_play_help _ _ =
let () = refocus_after_click () in
let () = Lwt.async (fun () -> f ()) in
Lwt.return_unit
in
let open Lwt_js_events in
let () = async (fun () ->
clicks help_dom on_play_help) in
play_help
let create_and_setup refocus_after_click create_animation start_animation param mode =
let height, width = 300, 700 in
let canvas = E.create_canvas_elt 300 700 in
let t = create_animation height width canvas in
let play_help = create_help_button refocus_after_click t (fun () -> start_animation t param) in
let elts = [canvas; play_help] in
let trs = List.map (fun elt -> Html5.(tr [td [elt]])) elts in
let anim_elt = Html5.(tablex ~a:[a_class ["centered"]] ~thead:(thead []) [tbody trs]) in
(Some (mode, t), [To_dom.of_element anim_elt])
let get_animation refocus_after_click question =
let mode, all_question, time = (question: question) in
let help_no_available = Html5.pcdata "Sorry that question does not have help for now" in
let not_available = None, [To_dom.of_element help_no_available] in
match mode with
| `Nor _ -> not_available
| `NorNori norNori -> begin
match time with
| `Past -> not_available
| `Present ->
let open E.NorNoriAnimation in
create_and_setup refocus_after_click create_animation start_animation norNori `NorNoriPresent
end
| `NorNork norNork -> begin
match time with
| `Past -> not_available
| `Present ->
let open E.NorNorkAnimation in
create_and_setup refocus_after_click create_animation start_animation norNork `NorNorkPresent
end
let get_help f question = get_animation f question
let stop_help h = stop_animation h
let is_there_help = true
end
module IndicativeClient = Games.Make(IndicativePastPresentClient)
}}
{server{
open Eliom_content
open Html5.D
let service unused unused_bis =
let _ = {unit{
let doc = Dom_html.document in
let parent =
Js.Opt.get (doc##getElementById(Js.string "main"))
(fun () -> assert false)
in
IndicativeClient.create_and_setup parent ()
}}
in
Games.return_page "indicative"
}}