aromancer 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.ruby-version +0 -1
- data/Gemfile.lock +37 -17
- data/README.md +5 -42
- data/aromancer.gemspec +2 -2
- data/bin/aromancer +1 -12
- data/checksums/aromancer-0.0.5.gem.sha512 +1 -0
- data/gem_graph.png +0 -0
- data/lib/aromancer/api.rb +7 -1
- data/lib/aromancer/prompt.rb +4 -0
- data/lib/aromancer/routes.rb +376 -170
- data/lib/aromancer/server.rb +16 -14
- data/lib/aromancer/storage.rb +131 -5
- data/lib/aromancer/version.rb +1 -1
- data/lib/aromancer/websocket.rb +65 -0
- data/lib/aromancer.rb +90 -0
- data/lib/reiquire.rb +1 -1
- data/locale/en.yml +15 -0
- metadata +19 -3
data/lib/aromancer/routes.rb
CHANGED
|
@@ -13,43 +13,159 @@
|
|
|
13
13
|
module Aromancer
|
|
14
14
|
class Routes
|
|
15
15
|
|
|
16
|
+
def self.resume
|
|
17
|
+
unless Thread.main[:route].nil?
|
|
18
|
+
if (Thread.main[:route_params] || []).any?
|
|
19
|
+
self.send(Thread.main[:route], *Thread.main[:route_params])
|
|
20
|
+
else
|
|
21
|
+
self.send(Thread.main[:route])
|
|
22
|
+
end
|
|
23
|
+
Thread.main[:route_params] = nil
|
|
24
|
+
Thread.main[:route] = nil
|
|
25
|
+
return
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
legend_menu if !active_legend.nil? &&
|
|
29
|
+
(Aromancer::Storage.get_player && Aromancer::Storage.get_player&.symbolize_keys[:active_legend_id])
|
|
30
|
+
authentication
|
|
31
|
+
end
|
|
32
|
+
|
|
16
33
|
def self.cls
|
|
17
|
-
TTY::
|
|
18
|
-
TTY::Cursor.
|
|
34
|
+
puts TTY::Screen.width
|
|
35
|
+
print TTY::Cursor.move(0, 0)
|
|
36
|
+
print TTY::Cursor.clear_screen
|
|
37
|
+
print TTY::Cursor.clear_screen_up
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.active_legend
|
|
41
|
+
Aromancer::Api.get_legends
|
|
42
|
+
|
|
43
|
+
(
|
|
44
|
+
Aromancer::Storage.get_legends&.select{|l| l["id"] == Aromancer::Storage.get_player["active_legend_id"]} || []
|
|
45
|
+
).first
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.arena_data
|
|
49
|
+
arena = Aromancer::Storage.get_arena
|
|
50
|
+
if arena.nil?
|
|
51
|
+
Aromancer.print_last_error("routes.legend.arena_failed")
|
|
52
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
53
|
+
main_menu
|
|
54
|
+
else
|
|
55
|
+
arena
|
|
56
|
+
end
|
|
19
57
|
end
|
|
20
58
|
|
|
21
|
-
def self.authentication
|
|
59
|
+
def self.authentication
|
|
60
|
+
if Aromancer::Storage.get_player
|
|
61
|
+
Aromancer::Storage.set_signed_out_flag(false)
|
|
62
|
+
return main_menu
|
|
63
|
+
end
|
|
22
64
|
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :authentication))
|
|
23
|
-
Aromancer::Prompt.p.ask(I18n.t("shared.key_press")) if require_key_press
|
|
24
65
|
|
|
25
66
|
choices = [
|
|
26
67
|
{name: I18n.t("routes.authentication.sign_in"), value: :in},
|
|
27
68
|
{name: I18n.t("routes.authentication.sign_up"), value: :up},
|
|
69
|
+
{name: I18n.t("routes.main_menu.configure"), value: :configure},
|
|
28
70
|
{name: I18n.t("shared.exit"), value: :exit}
|
|
29
71
|
]
|
|
30
|
-
text = ""#Aromancer.get_font(I18n.t("routes.authentication.title")).join("\n") +
|
|
31
|
-
"\n#{I18n.t("routes.authentication.subtitle")}"
|
|
32
|
-
case Aromancer::Prompt.p.select(text, choices, show_help: :always, cycle: true, per_page: 11)
|
|
33
|
-
when :in
|
|
34
|
-
Aromancer::Api.sign_in
|
|
35
|
-
when :up
|
|
36
|
-
Aromancer::Api.sign_up
|
|
37
|
-
else
|
|
38
|
-
exit
|
|
39
|
-
end
|
|
40
72
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
73
|
+
Thread.main[:input_controls] = {
|
|
74
|
+
choices: choices,
|
|
75
|
+
runners: [
|
|
76
|
+
{value: :in, proc: Proc.new{
|
|
77
|
+
Aromancer::Api.sign_in
|
|
78
|
+
authentication
|
|
79
|
+
}},
|
|
80
|
+
{value: :up, proc: Proc.new{
|
|
81
|
+
Aromancer::Api.sign_up
|
|
82
|
+
authentication
|
|
83
|
+
}},
|
|
84
|
+
{value: :configure, proc: Proc.new{
|
|
85
|
+
configure
|
|
86
|
+
}}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
Thread.main[:route] = __method__.to_s
|
|
48
90
|
end
|
|
49
91
|
|
|
50
|
-
def self.
|
|
51
|
-
|
|
52
|
-
|
|
92
|
+
def self.configure
|
|
93
|
+
cls
|
|
94
|
+
|
|
95
|
+
Aromancer::Prompt.say(I18n.t("routes.configure.title", name: Aromancer.to_s.downcase))
|
|
96
|
+
[
|
|
97
|
+
Aromancer::Storage.get_server_url,
|
|
98
|
+
Aromancer::Storage.get_websocket_url
|
|
99
|
+
].each{|l|
|
|
100
|
+
Aromancer::Prompt.say(l)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
choices = [
|
|
104
|
+
{name: I18n.t("shared.back"), value: :back},
|
|
105
|
+
{name: I18n.t("routes.configure.server_host", stored: Aromancer::Storage.instance.get_key(:server_url_host)), value: :host},
|
|
106
|
+
{name: I18n.t("routes.configure.server_port", stored: Aromancer::Storage.instance.get_key(:server_url_port)), value: :port},
|
|
107
|
+
{name: I18n.t("routes.configure.force_ssl", stored: Aromancer::Storage.get_preference(:force_ssl, default: true)), value: :force_ssl}
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
server_url_update = Proc.new{|property|
|
|
111
|
+
|
|
112
|
+
updated = nil
|
|
113
|
+
storage_key = "server_url_#{property}"
|
|
114
|
+
previous = Aromancer::Storage.instance.get_key(storage_key)
|
|
115
|
+
while updated.nil? || updated.blank? || updated != Aromancer::Storage.instance.get_key(storage_key)
|
|
116
|
+
# get user input
|
|
117
|
+
updated = Aromancer::Prompt.p.ask(I18n.t("routes.configure.new_#{property}"))
|
|
118
|
+
|
|
119
|
+
if property.to_sym == :port
|
|
120
|
+
updated = updated.to_i
|
|
121
|
+
next unless updated > 0
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# set new host value in storage
|
|
125
|
+
Aromancer::Storage.instance.set_key(storage_key, updated)
|
|
126
|
+
|
|
127
|
+
confirmed = false
|
|
128
|
+
begin
|
|
129
|
+
confirmed = Aromancer::Prompt.p.ask(I18n.t("shared.update_confirm", new_value: Aromancer::Storage.get_server_url))
|
|
130
|
+
rescue StandardError => e
|
|
131
|
+
Aromancer::Prompt.say(e)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
unless :y.to_s == confirmed
|
|
135
|
+
# reset to old value
|
|
136
|
+
Aromancer::Prompt.say(I18n.t("shared.update_cancel"))
|
|
137
|
+
Aromancer::Storage.instance.set_key(storage_key, previous)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
Aromancer::Storage.instance.clear_cache!
|
|
141
|
+
end
|
|
142
|
+
Aromancer::Prompt.say(I18n.t("shared.server_url", url: Aromancer::Storage.get_server_url))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
Thread.main[:input_controls] = {
|
|
146
|
+
choices: choices,
|
|
147
|
+
runners: [
|
|
148
|
+
{value: :back, proc: Proc.new{ main_menu }},
|
|
149
|
+
{value: :host, proc: Proc.new{
|
|
150
|
+
server_url_update.call(:host)
|
|
151
|
+
configure
|
|
152
|
+
}},
|
|
153
|
+
{value: :port, proc: Proc.new{
|
|
154
|
+
server_url_update.call(:port)
|
|
155
|
+
configure
|
|
156
|
+
}},
|
|
157
|
+
{value: :force_ssl, proc: Proc.new{
|
|
158
|
+
Aromancer::Storage.toggle_force_ssl
|
|
159
|
+
Aromancer::Prompt.say(I18n.t("shared.server_url", url: Aromancer::Storage.get_server_url))
|
|
160
|
+
Aromancer::Prompt.say(
|
|
161
|
+
I18n.t("routes.configure.force_ssl_toggle", value: Aromancer::Storage.get_preference(:force_ssl))
|
|
162
|
+
)
|
|
163
|
+
sleep(2)
|
|
164
|
+
configure
|
|
165
|
+
}},
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
Thread.main[:route] = __method__.to_s
|
|
53
169
|
end
|
|
54
170
|
|
|
55
171
|
def self.main_menu
|
|
@@ -66,36 +182,52 @@ module Aromancer
|
|
|
66
182
|
return legend_menu if (!player.nil? && !player[:active_legend_id].nil?) ||
|
|
67
183
|
(!al.nil? && al["status"] == "started")
|
|
68
184
|
|
|
185
|
+
return authentication if player.nil?
|
|
186
|
+
|
|
69
187
|
choices = [
|
|
70
188
|
{name: I18n.t("routes.main_menu.new_game"), value: :new},
|
|
71
189
|
{name: I18n.t("routes.main_menu.load_game"), value: :load},
|
|
190
|
+
{name: I18n.t("routes.main_menu.configure"), value: :configure},
|
|
72
191
|
{name: I18n.t("routes.main_menu.sign_out"), value: :out},
|
|
73
192
|
{name: I18n.t("shared.exit"), value: :exit}
|
|
74
193
|
]
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
194
|
+
|
|
195
|
+
Thread.main[:input_controls] = {
|
|
196
|
+
choices: choices,
|
|
197
|
+
runners: [
|
|
198
|
+
{value: :new, proc: Proc.new{
|
|
199
|
+
# this will run on the main thread
|
|
200
|
+
params = Aromancer::Api::DEFAULT_LEGEND_PARAMS.dup
|
|
201
|
+
|
|
202
|
+
player_count = nil
|
|
203
|
+
while player_count.nil? || ![1, 2].include?(player_count&.to_i)
|
|
204
|
+
player_count = Aromancer::Prompt.p.ask(I18n.t("routes.main_menu.player_count"))
|
|
205
|
+
end
|
|
206
|
+
params[:player_count] = player_count
|
|
207
|
+
new_game(params)
|
|
208
|
+
}},
|
|
209
|
+
{value: :load, proc: Proc.new{ Aromancer::Routes::legends }},
|
|
210
|
+
{value: :configure, proc: Proc.new{
|
|
211
|
+
configure
|
|
212
|
+
}},
|
|
213
|
+
{value: :out, proc: Proc.new{
|
|
214
|
+
case Aromancer::Prompt.p.select(I18n.t("shared.confirm"), [:no, :yes], cycle: true, per_page: 11)
|
|
215
|
+
when :no
|
|
216
|
+
main_menu
|
|
217
|
+
when :yes
|
|
218
|
+
Aromancer::Api.sign_out
|
|
219
|
+
authentication
|
|
220
|
+
end
|
|
221
|
+
}}
|
|
222
|
+
]
|
|
223
|
+
}
|
|
224
|
+
Thread.main[:route] = __method__.to_s
|
|
93
225
|
end
|
|
94
226
|
|
|
95
|
-
def self.new_game
|
|
227
|
+
def self.new_game(params)
|
|
96
228
|
cls
|
|
97
229
|
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :new_game))
|
|
98
|
-
|
|
230
|
+
|
|
99
231
|
data = [
|
|
100
232
|
[I18n.t("routes.new_game.player_count"), params[:player_count]],
|
|
101
233
|
[I18n.t("routes.new_game.story_count"), params[:story_count]],
|
|
@@ -104,13 +236,32 @@ module Aromancer
|
|
|
104
236
|
table = TTY::Table.new(data)
|
|
105
237
|
Aromancer::Prompt.say(table.render(:unicode))
|
|
106
238
|
|
|
107
|
-
# TODO: edit params here
|
|
108
|
-
|
|
109
239
|
Aromancer::Prompt.say(I18n.t("routes.new_game.starting"))
|
|
110
|
-
Aromancer::Api.create_legend(params)
|
|
111
|
-
Aromancer::Prompt.p.ask(I18n.t("shared.key_press"))
|
|
112
240
|
|
|
113
|
-
|
|
241
|
+
choices = [
|
|
242
|
+
{name: :continue, value: :continue},
|
|
243
|
+
{name: :cancel, value: :cancel}
|
|
244
|
+
]
|
|
245
|
+
Thread.main[:input_controls] = {
|
|
246
|
+
choices: choices,
|
|
247
|
+
runners: [
|
|
248
|
+
{value: :continue, proc: Proc.new{
|
|
249
|
+
Aromancer::Api.create_legend(params)
|
|
250
|
+
timeout = 1
|
|
251
|
+
while active_legend.nil? || timeout >= 11
|
|
252
|
+
Aromancer::Prompt.say(I18n.t("routes.new_game.starting"))
|
|
253
|
+
sleep(2)
|
|
254
|
+
timeout += 1
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
legend_menu
|
|
258
|
+
}},
|
|
259
|
+
{value: :cancel, proc: Proc.new{
|
|
260
|
+
Aromancer::Prompt.say(I18n.t("routes.new_game.cancelled"))
|
|
261
|
+
main_menu
|
|
262
|
+
}}
|
|
263
|
+
]
|
|
264
|
+
}
|
|
114
265
|
end
|
|
115
266
|
|
|
116
267
|
def self.legends
|
|
@@ -118,26 +269,36 @@ module Aromancer
|
|
|
118
269
|
legend_array = Aromancer::Storage.get_legends
|
|
119
270
|
unless legend_array.any?
|
|
120
271
|
Aromancer::Prompt.say(I18n.t("shared.empty"))
|
|
121
|
-
Aromancer::Prompt.p.ask(I18n.t("shared.key_press"))
|
|
272
|
+
# Aromancer::Prompt.p.ask(I18n.t("shared.key_press"))
|
|
122
273
|
main_menu
|
|
123
274
|
end
|
|
124
|
-
choices = [{name:
|
|
275
|
+
choices = [{name: I18n.t("shared.back"), value: :back}] + legend_array.map{|l|
|
|
125
276
|
{
|
|
126
277
|
name: "#{I18n.t("routes.legend.title")}_#{l["id"]} (#{l["status"]}) #{DateTime.parse(l["created_at"])&.strftime(Aromancer::Api::DATE_FORMAT)}",
|
|
127
278
|
value: l["id"]
|
|
128
279
|
}
|
|
129
280
|
}
|
|
130
|
-
selected_legend_id = Aromancer::Prompt.p.select("", choices, help: I18n.t("routes.legends.help"), show_help: :always, cycle: true, per_page: 11)
|
|
131
|
-
|
|
132
|
-
if selected_legend_id == :back
|
|
133
|
-
return main_menu
|
|
134
|
-
end
|
|
135
281
|
|
|
136
|
-
|
|
137
|
-
|
|
282
|
+
Thread.main[:input_controls] = {
|
|
283
|
+
choices: choices,
|
|
284
|
+
runners: [
|
|
285
|
+
{value: :back, proc: Proc.new{ main_menu }},
|
|
286
|
+
] + legend_array.map{|l|
|
|
287
|
+
{
|
|
288
|
+
value: l["id"],
|
|
289
|
+
proc: Proc.new{
|
|
290
|
+
Aromancer::Api.set_active_legend_id(l["id"])
|
|
291
|
+
legend_menu
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
Thread.main[:route] = __method__.to_s
|
|
138
297
|
end
|
|
139
298
|
|
|
140
299
|
def self.stream
|
|
300
|
+
# todo: this needs to be set as a view mode
|
|
301
|
+
# currently it gets overwritten
|
|
141
302
|
Aromancer::Api.load_stream
|
|
142
303
|
stream = Aromancer::Storage.get_stream
|
|
143
304
|
Aromancer::Prompt.say(I18n.t("routes.stream.title"))
|
|
@@ -150,22 +311,41 @@ module Aromancer
|
|
|
150
311
|
Aromancer::Prompt.say("\n")
|
|
151
312
|
Aromancer::Prompt.say([e["updated_at"], e["description"]].join("\n"))
|
|
152
313
|
}
|
|
153
|
-
|
|
154
|
-
|
|
314
|
+
|
|
315
|
+
Thread.main[:input_controls] = {
|
|
316
|
+
choices: [{name: I18n.t("shared.key_press"), value: nil}],
|
|
317
|
+
runners: [{value: nil, proc: Proc.new{ legend_menu }}]
|
|
318
|
+
}
|
|
319
|
+
Thread.main[:route] = __method__.to_s
|
|
155
320
|
end
|
|
156
321
|
|
|
157
322
|
def self.legend_menu
|
|
158
323
|
cls
|
|
159
|
-
# Aromancer::Prompt.say(I18n.t("shared.navigate", route: :legend_menu))
|
|
160
324
|
legend
|
|
161
325
|
|
|
162
326
|
legend_array = Aromancer::Storage.get_legends
|
|
163
327
|
al = active_legend
|
|
164
|
-
if !al.nil?
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
328
|
+
if !al.nil?
|
|
329
|
+
if al["status"] == "complete"
|
|
330
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
331
|
+
Aromancer::Prompt.say(I18n.t("routes.legend.legend_complete"))
|
|
332
|
+
# Aromancer::Prompt.p.ask(I18n.t("shared.key_press"))
|
|
333
|
+
return legends
|
|
334
|
+
elsif al["status"] == "created"
|
|
335
|
+
choices = [{name: :reload, value: :reload}, {name: I18n.t("shared.back"), value: :back}]
|
|
336
|
+
Thread.main[:input_controls] = {
|
|
337
|
+
choices: choices,
|
|
338
|
+
runners: [
|
|
339
|
+
{value: :reload, proc: Proc.new{ legend_menu }},
|
|
340
|
+
{value: :back, proc: Proc.new{
|
|
341
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
342
|
+
main_menu
|
|
343
|
+
}}
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
Thread.main[:route] = __method__.to_s
|
|
347
|
+
return
|
|
348
|
+
end
|
|
169
349
|
end
|
|
170
350
|
|
|
171
351
|
hs = Aromancer::Storage.get_preference(:hide_sentences, default: true)
|
|
@@ -178,30 +358,44 @@ module Aromancer
|
|
|
178
358
|
{name: I18n.t("routes.stream.title"), value: :stream},
|
|
179
359
|
{name: I18n.t("routes.main_menu.title"), value: :main_menu}
|
|
180
360
|
]
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
361
|
+
|
|
362
|
+
Thread.main[:input_controls] = {
|
|
363
|
+
choices: choices,
|
|
364
|
+
runners: [
|
|
365
|
+
{value: :words, proc: Proc.new{ words }},
|
|
366
|
+
{value: :spoken_words, proc: Proc.new{ spoken_words }},
|
|
367
|
+
{value: :unsigned_sentences, proc: Proc.new{ unsigned_sentences }},
|
|
368
|
+
{value: hs_value, proc: Proc.new{
|
|
369
|
+
Aromancer::Storage.set_preference(:hide_sentences, !hs)
|
|
370
|
+
legend_menu
|
|
371
|
+
}},
|
|
372
|
+
{value: :stream, proc: Proc.new{ stream }},
|
|
373
|
+
{value: :main_menu, proc: Proc.new{
|
|
374
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
375
|
+
main_menu
|
|
376
|
+
}},
|
|
377
|
+
]
|
|
378
|
+
}
|
|
379
|
+
Thread.main[:route] = __method__.to_s
|
|
199
380
|
end
|
|
200
381
|
|
|
201
382
|
def self.legend
|
|
202
383
|
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :legend))
|
|
203
384
|
Aromancer::Api.load_arena
|
|
204
385
|
arena = arena_data
|
|
386
|
+
al = active_legend
|
|
387
|
+
if !al.nil? && al["status"] == "created"
|
|
388
|
+
Aromancer::Prompt.say(arena["title"])
|
|
389
|
+
Aromancer::Prompt.say(I18n.t("routes.legend.players"))
|
|
390
|
+
Aromancer::Prompt.say(arena["players"].map{|p| p["alias"]})
|
|
391
|
+
# Aromancer::Prompt.p.ask(I18n.t("shared.key_press"))
|
|
392
|
+
return
|
|
393
|
+
elsif !al.nil? && al["status"] == "complete"
|
|
394
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
395
|
+
main_menu
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
return if arena.nil? || arena["turn_player"].nil?
|
|
205
399
|
|
|
206
400
|
# puts arena.to_json
|
|
207
401
|
turn_player = arena["turn_player"]
|
|
@@ -275,14 +469,67 @@ module Aromancer
|
|
|
275
469
|
legend
|
|
276
470
|
|
|
277
471
|
arena = arena_data
|
|
278
|
-
choices = [{name:
|
|
279
|
-
|
|
472
|
+
choices = [{name: I18n.t("shared.back"), value: :back}] + arena["player"]["words"].map{|w| {name: w["value_display"], value: w["id"]}}
|
|
473
|
+
|
|
474
|
+
Thread.main[:input_controls] = {
|
|
475
|
+
choices: choices,
|
|
476
|
+
runners: [
|
|
477
|
+
{value: :back, proc: Proc.new{ legend_menu }}
|
|
478
|
+
] + arena["player"]["words"].map{|w|
|
|
479
|
+
{value: w["id"], proc: Proc.new{
|
|
480
|
+
word(w["id"])
|
|
481
|
+
}}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
Thread.main[:route] = __method__.to_s
|
|
485
|
+
end
|
|
280
486
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
487
|
+
def self.spoken_words
|
|
488
|
+
cls
|
|
489
|
+
legend
|
|
490
|
+
|
|
491
|
+
arena = arena_data
|
|
492
|
+
choices = [{name: I18n.t("shared.back"), value: :back}] + arena["scroll_words"].map{|w| {name: w["value_display"], value: w["id"]}}
|
|
493
|
+
|
|
494
|
+
Thread.main[:input_controls] = {
|
|
495
|
+
choices: choices,
|
|
496
|
+
runners: [
|
|
497
|
+
{value: :back, proc: Proc.new{ legend_menu }}
|
|
498
|
+
] + arena["scroll_words"].map{|w|
|
|
499
|
+
{value: w["id"], proc: Proc.new{
|
|
500
|
+
word(w["id"])
|
|
501
|
+
}}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
Thread.main[:route] = __method__.to_s
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
def self.unsigned_sentences
|
|
508
|
+
cls
|
|
509
|
+
legend
|
|
284
510
|
|
|
285
|
-
|
|
511
|
+
arena = arena_data
|
|
512
|
+
choices = [{name: I18n.t("shared.back"), value: :back}] + arena["sentences"].map{|s| {name: "id: #{s["id"]}, value: #{s["value"]}", value: s["id"]}}
|
|
513
|
+
|
|
514
|
+
Thread.main[:input_controls] = {
|
|
515
|
+
choices: choices,
|
|
516
|
+
runners: [
|
|
517
|
+
{value: :back, proc: Proc.new{ legend_menu }}
|
|
518
|
+
] + arena["sentences"].map{|s|
|
|
519
|
+
ss_words = s["words"]
|
|
520
|
+
wid = ss_words.first["id"]
|
|
521
|
+
{value: s["id"], proc: Proc.new{
|
|
522
|
+
|
|
523
|
+
# todo: probably do not need this check
|
|
524
|
+
# if ss_words.nil? || ss_words.empty?
|
|
525
|
+
# legend_menu
|
|
526
|
+
# else
|
|
527
|
+
word(wid)
|
|
528
|
+
# end
|
|
529
|
+
}}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
Thread.main[:route] = __method__.to_s
|
|
286
533
|
end
|
|
287
534
|
|
|
288
535
|
def self.word(selected_word_id)
|
|
@@ -292,7 +539,7 @@ module Aromancer
|
|
|
292
539
|
possibilities = Aromancer::Api.load_word_possibilities(selected_word_id)
|
|
293
540
|
|
|
294
541
|
# todo: hide/show this
|
|
295
|
-
puts JSON.pretty_generate possibilities
|
|
542
|
+
# puts JSON.pretty_generate possibilities
|
|
296
543
|
|
|
297
544
|
options = possibilities["options"]
|
|
298
545
|
selected_word = possibilities["word"]
|
|
@@ -322,93 +569,52 @@ module Aromancer
|
|
|
322
569
|
|
|
323
570
|
"#{sw["value_display"]} #{a} #{o_value_display} #{calc}"
|
|
324
571
|
}
|
|
325
|
-
|
|
572
|
+
place_title = I18n.t("routes.legend.place_on_scroll", word: selected_word["value_display"])
|
|
326
573
|
choices = [
|
|
327
|
-
{name:
|
|
574
|
+
{name: I18n.t("shared.back"), value: :back}
|
|
328
575
|
]
|
|
329
576
|
if for_type == :player_word
|
|
330
577
|
# show place on scroll option if selected word is from player's words
|
|
331
|
-
choices << {name:
|
|
578
|
+
choices << {name: place_title, value: :player_word}
|
|
332
579
|
end
|
|
333
580
|
choices += options.map{|o| {name: option_display.call(o, selected_word), value: o}}
|
|
334
|
-
selected_option = Aromancer::Prompt.p.select(
|
|
335
|
-
I18n.t("routes.legend.options_for_word", word: selected_word["value_display"]),
|
|
336
|
-
choices,
|
|
337
|
-
show_help: :always, cycle: true, per_page: 11
|
|
338
|
-
)
|
|
339
|
-
|
|
340
|
-
if selected_option == :back
|
|
341
|
-
return case for_type
|
|
342
|
-
when :player_word
|
|
343
|
-
words
|
|
344
|
-
when :scroll_word
|
|
345
|
-
spoken_words
|
|
346
|
-
when :scroll_sentence
|
|
347
|
-
unsigned_sentences
|
|
348
|
-
end
|
|
349
|
-
elsif selected_option == :player_word
|
|
350
|
-
wytyd = I18n.t("routes.legend.place_on_scroll", word: selected_word["value_display"])
|
|
351
|
-
Aromancer::Prompt.say(wytyd)
|
|
352
|
-
Aromancer::Api.create_turn({
|
|
353
|
-
wytyd: wytyd,
|
|
354
|
-
word_id: selected_word["id"]
|
|
355
|
-
})
|
|
356
|
-
legend_menu
|
|
357
|
-
else
|
|
358
|
-
if selected_option["http_verb"] == "post"
|
|
359
|
-
Aromancer::Api.create_turn(JSON.parse(selected_option["payload"]))
|
|
360
|
-
else
|
|
361
|
-
Aromancer::Api.update_turn(JSON.parse(selected_option["payload"]))
|
|
362
|
-
end
|
|
363
581
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return legend_menu if ss_words.nil? || ss_words.empty?
|
|
582
|
+
Thread.main[:input_controls] = {
|
|
583
|
+
choices: choices,
|
|
584
|
+
runners: [
|
|
585
|
+
{value: :back, proc: Proc.new{
|
|
586
|
+
case for_type
|
|
587
|
+
when :player_word
|
|
588
|
+
words
|
|
589
|
+
when :scroll_word
|
|
590
|
+
spoken_words
|
|
591
|
+
when :scroll_sentence
|
|
592
|
+
unsigned_sentences
|
|
593
|
+
end
|
|
594
|
+
}},
|
|
595
|
+
{value: :player_word, proc: Proc.new{
|
|
596
|
+
wytyd = I18n.t("routes.legend.place_on_scroll", word: selected_word["value_display"])
|
|
597
|
+
Aromancer::Prompt.say(wytyd)
|
|
598
|
+
Aromancer::Api.create_turn({
|
|
599
|
+
wytyd: wytyd,
|
|
600
|
+
word_id: selected_word["id"]
|
|
601
|
+
})
|
|
602
|
+
legend_menu
|
|
603
|
+
}},
|
|
604
|
+
{value: nil, proc: Proc.new{|o|
|
|
605
|
+
if o["http_verb"] == "post"
|
|
606
|
+
Aromancer::Api.create_turn(JSON.parse(o["payload"]))
|
|
607
|
+
else
|
|
608
|
+
Aromancer::Api.update_turn(JSON.parse(o["payload"]))
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
legend_menu
|
|
612
|
+
}}
|
|
613
|
+
]
|
|
614
|
+
}
|
|
398
615
|
|
|
399
|
-
|
|
616
|
+
Thread.main[:route] = __method__.to_s
|
|
617
|
+
Thread.main[:route_params] = [selected_word_id]
|
|
400
618
|
end
|
|
401
|
-
|
|
402
|
-
def self.arena_data
|
|
403
|
-
arena = Aromancer::Storage.get_arena
|
|
404
|
-
if arena.nil?
|
|
405
|
-
Aromancer.print_last_error("routes.legend.arena_failed")
|
|
406
|
-
Aromancer::Api.set_active_legend_id(nil)
|
|
407
|
-
main_menu
|
|
408
|
-
else
|
|
409
|
-
arena
|
|
410
|
-
end
|
|
411
|
-
end
|
|
412
|
-
|
|
413
619
|
end
|
|
414
620
|
end
|