aromancer 0.0.4 → 0.0.6
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 +1 -43
- data/aromancer.gemspec +2 -2
- data/bin/aromancer +1 -12
- data/checksums/aromancer-0.0.5.gem.sha512 +1 -0
- data/checksums/aromancer-0.0.6.gem.sha512 +1 -0
- data/gem_graph.png +0 -0
- data/lib/aromancer/api.rb +31 -15
- data/lib/aromancer/prompt.rb +4 -0
- data/lib/aromancer/routes.rb +451 -237
- data/lib/aromancer/server.rb +53 -41
- data/lib/aromancer/storage.rb +137 -5
- data/lib/aromancer/version.rb +1 -1
- data/lib/aromancer/websocket.rb +82 -0
- data/lib/aromancer.rb +123 -1
- data/lib/reiquire.rb +1 -1
- data/locale/en.yml +21 -1
- metadata +20 -3
data/lib/aromancer/routes.rb
CHANGED
|
@@ -13,51 +13,183 @@
|
|
|
13
13
|
module Aromancer
|
|
14
14
|
class Routes
|
|
15
15
|
|
|
16
|
+
def self.resume
|
|
17
|
+
return main_menu if Aromancer::Storage.get_signed_out_flag
|
|
18
|
+
|
|
19
|
+
unless Thread.main[:route].nil?
|
|
20
|
+
begin
|
|
21
|
+
Thread.main[:route_params] ||= []
|
|
22
|
+
if Thread.main[:route_params].any?
|
|
23
|
+
self.send(Thread.main[:route], *Thread.main[:route_params])
|
|
24
|
+
Thread.main[:route_params] = []
|
|
25
|
+
else
|
|
26
|
+
self.send(Thread.main[:route])
|
|
27
|
+
end
|
|
28
|
+
rescue ArgumentError => e
|
|
29
|
+
authentication
|
|
30
|
+
end
|
|
31
|
+
return
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
legend_menu if !active_legend.nil? &&
|
|
35
|
+
(Aromancer::Storage.get_player && Aromancer::Storage.get_player&.symbolize_keys[:active_legend_id])
|
|
36
|
+
authentication
|
|
37
|
+
end
|
|
38
|
+
|
|
16
39
|
def self.cls
|
|
17
|
-
TTY::
|
|
18
|
-
TTY::Cursor.
|
|
40
|
+
puts TTY::Screen.width
|
|
41
|
+
print TTY::Cursor.move(0, 0)
|
|
42
|
+
print TTY::Cursor.clear_screen
|
|
43
|
+
print TTY::Cursor.clear_screen_up
|
|
19
44
|
end
|
|
20
45
|
|
|
21
|
-
def self.
|
|
22
|
-
|
|
23
|
-
|
|
46
|
+
def self.active_legend
|
|
47
|
+
(
|
|
48
|
+
Aromancer::Storage.get_legends&.select{|l| l["id"] == (Aromancer::Storage.get_player || {})["active_legend_id"]} || []
|
|
49
|
+
).first
|
|
50
|
+
end
|
|
24
51
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Aromancer::Api.
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
def self.arena_data
|
|
53
|
+
arena = Aromancer::Storage.get_arena
|
|
54
|
+
if arena.nil?
|
|
55
|
+
Aromancer::Api.load_arena
|
|
56
|
+
sleep(1)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
if arena.nil?
|
|
60
|
+
Aromancer.print_last_error("routes.legend.arena_failed")
|
|
61
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
62
|
+
Aromancer::Prompt.p.ask(I18n.t("shared.key_press"))
|
|
63
|
+
main_menu
|
|
37
64
|
else
|
|
38
|
-
|
|
65
|
+
arena
|
|
39
66
|
end
|
|
67
|
+
end
|
|
40
68
|
|
|
69
|
+
def self.authentication
|
|
41
70
|
if Aromancer::Storage.get_player
|
|
42
71
|
Aromancer::Storage.set_signed_out_flag(false)
|
|
43
|
-
main_menu
|
|
44
|
-
else
|
|
45
|
-
Aromancer.print_last_error("routes.authentication.failed")
|
|
46
|
-
authentication(true)
|
|
72
|
+
return main_menu
|
|
47
73
|
end
|
|
74
|
+
|
|
75
|
+
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :authentication)) if Aromancer::Storage.get_preference(:debug)
|
|
76
|
+
|
|
77
|
+
Thread.main[:menu_options][__method__.to_sym] ||= [
|
|
78
|
+
{name: I18n.t("routes.authentication.sign_in"), value: :in},
|
|
79
|
+
{name: I18n.t("routes.authentication.sign_up"), value: :up},
|
|
80
|
+
{name: I18n.t("routes.main_menu.configure"), value: :configure},
|
|
81
|
+
{name: I18n.t("shared.exit"), value: :exit}
|
|
82
|
+
]
|
|
83
|
+
Thread.main[:menu_runners][__method__.to_sym] ||= [
|
|
84
|
+
{value: :in, proc: Proc.new{
|
|
85
|
+
Aromancer::Api.sign_in
|
|
86
|
+
authentication
|
|
87
|
+
}},
|
|
88
|
+
{value: :up, proc: Proc.new{
|
|
89
|
+
Aromancer::Api.sign_up
|
|
90
|
+
authentication
|
|
91
|
+
}},
|
|
92
|
+
{value: :configure, proc: Proc.new{
|
|
93
|
+
configure
|
|
94
|
+
}}
|
|
95
|
+
]
|
|
96
|
+
Thread.main[:route] = __method__.to_sym
|
|
48
97
|
end
|
|
49
98
|
|
|
50
|
-
def self.
|
|
51
|
-
|
|
52
|
-
|
|
99
|
+
def self.configure
|
|
100
|
+
cls
|
|
101
|
+
|
|
102
|
+
Aromancer::Prompt.say(I18n.t("routes.configure.title", name: Aromancer.to_s.downcase))
|
|
103
|
+
[
|
|
104
|
+
Aromancer::Storage.get_server_url,
|
|
105
|
+
Aromancer::Storage.get_websocket_url
|
|
106
|
+
].each{|l|
|
|
107
|
+
Aromancer::Prompt.say(l)
|
|
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[:menu_options][__method__.to_sym] = [
|
|
146
|
+
{name: I18n.t("shared.back"), value: :back},
|
|
147
|
+
{name: I18n.t("routes.configure.server_host", stored: Aromancer::Storage.instance.get_key(:server_url_host)), value: :host},
|
|
148
|
+
{name: I18n.t("routes.configure.server_port", stored: Aromancer::Storage.instance.get_key(:server_url_port)), value: :port},
|
|
149
|
+
{name: I18n.t("routes.configure.force_ssl", stored: Aromancer::Storage.get_preference(:force_ssl)), value: :force_ssl},
|
|
150
|
+
{name: I18n.t("routes.configure.debug", stored: Aromancer::Storage.get_preference(:debug)), value: :debug}
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
Thread.main[:menu_runners][__method__.to_sym] = [
|
|
154
|
+
{value: :back, proc: Proc.new{ main_menu }},
|
|
155
|
+
{value: :host, proc: Proc.new{
|
|
156
|
+
server_url_update.call(:host)
|
|
157
|
+
configure
|
|
158
|
+
}},
|
|
159
|
+
{value: :port, proc: Proc.new{
|
|
160
|
+
server_url_update.call(:port)
|
|
161
|
+
configure
|
|
162
|
+
}},
|
|
163
|
+
{value: :force_ssl, proc: Proc.new{
|
|
164
|
+
Aromancer::Storage.toggle_force_ssl
|
|
165
|
+
Aromancer::Prompt.say(I18n.t("shared.server_url", url: Aromancer::Storage.get_server_url))
|
|
166
|
+
Aromancer::Prompt.say(
|
|
167
|
+
I18n.t("routes.configure.force_ssl_toggle", value: Aromancer::Storage.get_preference(:force_ssl))
|
|
168
|
+
)
|
|
169
|
+
sleep(2)
|
|
170
|
+
configure
|
|
171
|
+
}},
|
|
172
|
+
{value: :debug, proc: Proc.new{
|
|
173
|
+
Aromancer::Storage.toggle_preference(:debug)
|
|
174
|
+
|
|
175
|
+
Aromancer::Prompt.say(
|
|
176
|
+
I18n.t("routes.configure.debug_toggle", value: Aromancer::Storage.get_preference(:debug))
|
|
177
|
+
)
|
|
178
|
+
sleep(2)
|
|
179
|
+
configure
|
|
180
|
+
}},
|
|
181
|
+
]
|
|
182
|
+
Thread.main[:route] = __method__.to_sym
|
|
53
183
|
end
|
|
54
184
|
|
|
55
185
|
def self.main_menu
|
|
56
186
|
cls
|
|
57
|
-
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :main_menu))
|
|
187
|
+
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :main_menu)) if Aromancer::Storage.get_preference(:debug)
|
|
58
188
|
if Aromancer::Storage.get_signed_out_flag
|
|
59
189
|
Aromancer::Prompt.say(I18n.t("routes.main_menu.not_signed_in"))
|
|
60
190
|
Aromancer::Api.sign_out
|
|
191
|
+
Thread.main[:route] = :authentication
|
|
192
|
+
Thread.main[:menu_options] = {}
|
|
61
193
|
return authentication
|
|
62
194
|
end
|
|
63
195
|
|
|
@@ -66,36 +198,52 @@ module Aromancer
|
|
|
66
198
|
return legend_menu if (!player.nil? && !player[:active_legend_id].nil?) ||
|
|
67
199
|
(!al.nil? && al["status"] == "started")
|
|
68
200
|
|
|
69
|
-
|
|
201
|
+
return authentication if player.nil?
|
|
202
|
+
|
|
203
|
+
Thread.main[:menu_options][__method__.to_sym] ||= [
|
|
70
204
|
{name: I18n.t("routes.main_menu.new_game"), value: :new},
|
|
71
205
|
{name: I18n.t("routes.main_menu.load_game"), value: :load},
|
|
206
|
+
{name: I18n.t("routes.main_menu.find_game"), value: :find},
|
|
207
|
+
{name: I18n.t("routes.main_menu.configure"), value: :configure},
|
|
72
208
|
{name: I18n.t("routes.main_menu.sign_out"), value: :out},
|
|
73
209
|
{name: I18n.t("shared.exit"), value: :exit}
|
|
74
210
|
]
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
211
|
+
|
|
212
|
+
Thread.main[:menu_runners][__method__.to_sym] = [
|
|
213
|
+
{value: :new, proc: Proc.new{
|
|
214
|
+
# this will run on the main thread
|
|
215
|
+
params = Aromancer::Api::DEFAULT_LEGEND_PARAMS.dup
|
|
216
|
+
|
|
217
|
+
player_count = nil
|
|
218
|
+
while player_count.nil? || ![1, 2].include?(player_count&.to_i)
|
|
219
|
+
player_count = Aromancer::Prompt.p.ask(I18n.t("routes.main_menu.player_count"))
|
|
220
|
+
end
|
|
221
|
+
params[:player_count] = player_count
|
|
222
|
+
Thread.main[:route_params] = [params]
|
|
223
|
+
new_game(params)
|
|
224
|
+
}},
|
|
225
|
+
{value: :load, proc: Proc.new{ Aromancer::Routes::legends }},
|
|
226
|
+
{value: :find, proc: Proc.new{ Aromancer::Routes::find_game }},
|
|
227
|
+
{value: :configure, proc: Proc.new{
|
|
228
|
+
configure
|
|
229
|
+
}},
|
|
230
|
+
{value: :out, proc: Proc.new{
|
|
231
|
+
case Aromancer::Prompt.p.select(I18n.t("shared.confirm"), [:no, :yes], cycle: true, per_page: 11)
|
|
232
|
+
when :no
|
|
233
|
+
main_menu
|
|
234
|
+
when :yes
|
|
235
|
+
Aromancer::Api.sign_out
|
|
236
|
+
authentication
|
|
237
|
+
end
|
|
238
|
+
}}
|
|
239
|
+
]
|
|
240
|
+
Thread.main[:route] = __method__.to_sym
|
|
93
241
|
end
|
|
94
242
|
|
|
95
|
-
def self.new_game
|
|
243
|
+
def self.new_game(params)
|
|
96
244
|
cls
|
|
97
|
-
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :new_game))
|
|
98
|
-
|
|
245
|
+
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :new_game)) if Aromancer::Storage.get_preference(:debug)
|
|
246
|
+
|
|
99
247
|
data = [
|
|
100
248
|
[I18n.t("routes.new_game.player_count"), params[:player_count]],
|
|
101
249
|
[I18n.t("routes.new_game.story_count"), params[:story_count]],
|
|
@@ -104,37 +252,83 @@ module Aromancer
|
|
|
104
252
|
table = TTY::Table.new(data)
|
|
105
253
|
Aromancer::Prompt.say(table.render(:unicode))
|
|
106
254
|
|
|
107
|
-
# TODO: edit params here
|
|
108
|
-
|
|
109
255
|
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
256
|
|
|
113
|
-
|
|
257
|
+
Thread.main[:menu_options][__method__.to_sym] = [
|
|
258
|
+
{name: :continue, value: :continue},
|
|
259
|
+
{name: :cancel, value: :cancel}
|
|
260
|
+
]
|
|
261
|
+
Thread.main[:menu_runners][__method__.to_sym] = [
|
|
262
|
+
{value: :continue, proc: Proc.new{
|
|
263
|
+
Aromancer::Storage.instance.clear_cache!
|
|
264
|
+
Aromancer::Api.create_legend(params)
|
|
265
|
+
legend_menu
|
|
266
|
+
# Aromancer::Api.get_legends
|
|
267
|
+
|
|
268
|
+
# unless active_legend.nil? || active_legend["id"] != Aromancer::Storage.get_player["active_legend_id"]
|
|
269
|
+
# Aromancer.print_last_error
|
|
270
|
+
# sleep(1)
|
|
271
|
+
# main_menu
|
|
272
|
+
# else
|
|
273
|
+
# legend_menu
|
|
274
|
+
# end
|
|
275
|
+
}},
|
|
276
|
+
{value: :cancel, proc: Proc.new{
|
|
277
|
+
Aromancer::Prompt.say(I18n.t("routes.new_game.cancelled"))
|
|
278
|
+
main_menu
|
|
279
|
+
}}
|
|
280
|
+
]
|
|
281
|
+
Thread.main[:route] = __method__.to_sym
|
|
114
282
|
end
|
|
115
283
|
|
|
116
|
-
def self.
|
|
117
|
-
Aromancer::
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
284
|
+
def self.find_game
|
|
285
|
+
legends(JSON.parse(Aromancer::Server.find_legends.body || []))
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def self.legends(legend_array = nil)
|
|
289
|
+
|
|
290
|
+
# if legend_array.nil?, load player's legends
|
|
291
|
+
if legend_array.nil?
|
|
292
|
+
Aromancer::Storage.instance.clear_cache!
|
|
293
|
+
Aromancer::Api.get_legends
|
|
294
|
+
legend_array = Aromancer::Storage.get_legends
|
|
295
|
+
unless legend_array.any?
|
|
296
|
+
Aromancer::Prompt.say(I18n.t("shared.empty"))
|
|
297
|
+
sleep(1)
|
|
298
|
+
return main_menu
|
|
299
|
+
end
|
|
123
300
|
end
|
|
124
|
-
|
|
301
|
+
|
|
302
|
+
Thread.main[:menu_options][__method__.to_sym] = [{name: I18n.t("shared.back"), value: :back}] + legend_array.map{|l|
|
|
125
303
|
{
|
|
126
304
|
name: "#{I18n.t("routes.legend.title")}_#{l["id"]} (#{l["status"]}) #{DateTime.parse(l["created_at"])&.strftime(Aromancer::Api::DATE_FORMAT)}",
|
|
127
305
|
value: l["id"]
|
|
128
306
|
}
|
|
129
307
|
}
|
|
130
|
-
selected_legend_id = Aromancer::Prompt.p.select("", choices, help: I18n.t("routes.legends.help"), show_help: :always, cycle: true, per_page: 11)
|
|
131
308
|
|
|
132
|
-
if
|
|
133
|
-
|
|
309
|
+
if Aromancer::Storage.get_preference(:debug)
|
|
310
|
+
Aromancer::Prompt.say(JSON.pretty_generate(legend_array))
|
|
134
311
|
end
|
|
135
312
|
|
|
136
|
-
|
|
137
|
-
|
|
313
|
+
Thread.main[:menu_runners][__method__.to_sym] = [
|
|
314
|
+
{value: :back, proc: Proc.new{ main_menu }},
|
|
315
|
+
] + legend_array.map{|l|
|
|
316
|
+
{
|
|
317
|
+
value: l["id"],
|
|
318
|
+
proc: Proc.new{
|
|
319
|
+
Aromancer::Api.set_active_legend_id(l["id"])
|
|
320
|
+
|
|
321
|
+
unless active_legend.nil? || active_legend["id"] != Aromancer::Storage.get_player["active_legend_id"]
|
|
322
|
+
Aromancer.print_last_error
|
|
323
|
+
sleep(1)
|
|
324
|
+
main_menu
|
|
325
|
+
else
|
|
326
|
+
legend_menu
|
|
327
|
+
end
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
Thread.main[:route] = __method__.to_sym
|
|
138
332
|
end
|
|
139
333
|
|
|
140
334
|
def self.stream
|
|
@@ -150,27 +344,45 @@ module Aromancer
|
|
|
150
344
|
Aromancer::Prompt.say("\n")
|
|
151
345
|
Aromancer::Prompt.say([e["updated_at"], e["description"]].join("\n"))
|
|
152
346
|
}
|
|
153
|
-
|
|
154
|
-
|
|
347
|
+
|
|
348
|
+
Thread.main[:menu_options][__method__.to_sym] ||= [{name: I18n.t("shared.key_press"), value: nil}]
|
|
349
|
+
Thread.main[:menu_runners][__method__.to_sym] ||= [
|
|
350
|
+
{value: nil, proc: Proc.new{ legend_menu }}
|
|
351
|
+
]
|
|
352
|
+
Thread.main[:route] = __method__.to_sym
|
|
155
353
|
end
|
|
156
354
|
|
|
157
355
|
def self.legend_menu
|
|
158
356
|
cls
|
|
159
|
-
# Aromancer::Prompt.say(I18n.t("shared.navigate", route: :legend_menu))
|
|
160
357
|
legend
|
|
161
358
|
|
|
162
359
|
legend_array = Aromancer::Storage.get_legends
|
|
163
360
|
al = active_legend
|
|
164
|
-
if !al.nil?
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
361
|
+
if !al.nil?
|
|
362
|
+
if al["status"] == "complete"
|
|
363
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
364
|
+
Aromancer::Prompt.say(I18n.t("routes.legend.legend_complete"))
|
|
365
|
+
return legends
|
|
366
|
+
elsif al["status"] == "created"
|
|
367
|
+
Thread.main[:menu_options][__method__.to_sym] = [
|
|
368
|
+
{name: :reload, value: :reload}, {name: I18n.t("shared.back"), value: :back}
|
|
369
|
+
]
|
|
370
|
+
Thread.main[:menu_runners][__method__.to_sym] ||= [
|
|
371
|
+
{value: :reload, proc: Proc.new{ legend_menu }},
|
|
372
|
+
{value: :back, proc: Proc.new{
|
|
373
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
374
|
+
main_menu
|
|
375
|
+
}}
|
|
376
|
+
]
|
|
377
|
+
Thread.main[:route] = __method__.to_sym
|
|
378
|
+
return
|
|
379
|
+
end
|
|
169
380
|
end
|
|
170
|
-
|
|
171
|
-
hs = Aromancer::Storage.get_preference(:hide_sentences, default: true)
|
|
381
|
+
hs = Aromancer::Storage.get_preference(:hide_sentences)
|
|
172
382
|
hs_value = "#{hs ? "" : "hide_"}signed_sentences".to_sym
|
|
173
|
-
|
|
383
|
+
|
|
384
|
+
Thread.main[:route] = __method__.to_sym
|
|
385
|
+
Thread.main[:menu_options][__method__.to_sym] = [
|
|
174
386
|
{name: I18n.t("routes.legend.unspoken_words"), value: :words},
|
|
175
387
|
{name: I18n.t("routes.legend.spoken_words"), value: :spoken_words},
|
|
176
388
|
{name: I18n.t("routes.legend.unsigned_sentences"), value: :unsigned_sentences},
|
|
@@ -178,43 +390,63 @@ module Aromancer
|
|
|
178
390
|
{name: I18n.t("routes.stream.title"), value: :stream},
|
|
179
391
|
{name: I18n.t("routes.main_menu.title"), value: :main_menu}
|
|
180
392
|
]
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
Aromancer::Api.set_active_legend_id(nil)
|
|
197
|
-
main_menu
|
|
198
|
-
end
|
|
393
|
+
|
|
394
|
+
Thread.main[:menu_runners][__method__.to_sym] = [
|
|
395
|
+
{value: :words, proc: Proc.new{ words }},
|
|
396
|
+
{value: :spoken_words, proc: Proc.new{ spoken_words }},
|
|
397
|
+
{value: :unsigned_sentences, proc: Proc.new{ unsigned_sentences }},
|
|
398
|
+
{value: hs_value, proc: Proc.new{
|
|
399
|
+
Aromancer::Storage.toggle_preference(:hide_sentences)
|
|
400
|
+
legend_menu
|
|
401
|
+
}},
|
|
402
|
+
{value: :stream, proc: Proc.new{ stream }},
|
|
403
|
+
{value: :main_menu, proc: Proc.new{
|
|
404
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
405
|
+
main_menu
|
|
406
|
+
}},
|
|
407
|
+
]
|
|
199
408
|
end
|
|
200
409
|
|
|
201
410
|
def self.legend
|
|
202
|
-
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :legend))
|
|
411
|
+
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :legend)) if Aromancer::Storage.get_preference(:debug)
|
|
203
412
|
Aromancer::Api.load_arena
|
|
204
413
|
arena = arena_data
|
|
414
|
+
al = active_legend
|
|
415
|
+
al_status = ((al || {})["status"] || "").to_sym
|
|
416
|
+
if !al.nil? &&
|
|
417
|
+
[:created, :complete].include?(al_status)
|
|
418
|
+
Aromancer::Prompt.say(arena["title"])
|
|
419
|
+
Aromancer::Prompt.say(I18n.t("routes.legend.title"))
|
|
420
|
+
Aromancer::Prompt.say(I18n.t("routes.legend.subtitle", subtitle: al["status"]))
|
|
421
|
+
Aromancer::Prompt.say(I18n.t("routes.legend.players"))
|
|
422
|
+
Aromancer::Prompt.say(JSON.pretty_generate(arena["players"]))
|
|
423
|
+
Aromancer::Prompt.p.ask(I18n.t("shared.key_press"))
|
|
424
|
+
if al_status == :complete
|
|
425
|
+
Aromancer::Api.set_active_legend_id(nil)
|
|
426
|
+
sleep(1)
|
|
427
|
+
return main_menu
|
|
428
|
+
else
|
|
429
|
+
Aromancer::Api.get_legends
|
|
430
|
+
legend_menu
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
return if arena.nil? || arena["turn_player"].nil?
|
|
435
|
+
|
|
436
|
+
# todo: pre-calculate needed widths. this isn't really working
|
|
437
|
+
word_width = 5.0
|
|
438
|
+
wpr = (TTY::Screen.width / word_width).floor
|
|
439
|
+
|
|
440
|
+
# puts "wpr: #{wpr}"
|
|
441
|
+
# puts TTY::Screen.width
|
|
205
442
|
|
|
206
|
-
# puts arena.to_json
|
|
207
443
|
turn_player = arena["turn_player"]
|
|
208
444
|
|
|
209
445
|
# title
|
|
210
446
|
Aromancer::Prompt.say("\n\n")
|
|
211
447
|
data = [
|
|
212
448
|
[arena["title"]],
|
|
213
|
-
["#{
|
|
214
|
-
turn_player["id"] == Aromancer::Storage.get_player["id"] ?
|
|
215
|
-
"your" :
|
|
216
|
-
"#{turn_player["alias"]}'s"
|
|
217
|
-
} turn"],
|
|
449
|
+
["#{turn_player["alias"]}'s turn"],
|
|
218
450
|
["dealer is #{arena["dealer"]["alias"]}"]
|
|
219
451
|
]
|
|
220
452
|
title_table = TTY::Table.new(data)
|
|
@@ -222,51 +454,52 @@ module Aromancer
|
|
|
222
454
|
|
|
223
455
|
# players
|
|
224
456
|
data = [
|
|
225
|
-
[I18n.t("routes.legend.players")] + arena["players"].map{|p| p["alias"]}
|
|
457
|
+
[I18n.t("routes.legend.players")] + arena["players"].map{|p| "#{p["alias"]} (#{p["score"]})"}
|
|
226
458
|
]
|
|
227
459
|
players_table = TTY::Table.new(data)
|
|
228
460
|
Aromancer::Prompt.say(players_table.render(:ascii))
|
|
229
461
|
|
|
230
462
|
# spoken words
|
|
231
463
|
Aromancer::Prompt.say(I18n.t("routes.legend.spoken_words"))
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
464
|
+
|
|
465
|
+
data = arena["scroll_words"].map{|sw| sw["value_display"]}.each_slice(wpr).to_a || []
|
|
466
|
+
while data.any? && data.last.length < data.first.length
|
|
467
|
+
data.last << ""
|
|
468
|
+
end
|
|
235
469
|
spoken_words_table = TTY::Table.new(data)
|
|
236
470
|
Aromancer::Prompt.say(spoken_words_table.render(:unicode))
|
|
237
471
|
|
|
238
472
|
unless arena["sentences"].empty?
|
|
239
473
|
# unsigned sentences
|
|
240
474
|
Aromancer::Prompt.say(I18n.t("routes.legend.unsigned_sentences"))
|
|
241
|
-
data = [
|
|
242
|
-
|
|
243
|
-
|
|
475
|
+
data = arena["sentences"].map{|sw| sw["value_display"]}.each_slice(wpr).to_a || []
|
|
476
|
+
while data.any? && data.last.length < data.first.length
|
|
477
|
+
data.last << ""
|
|
478
|
+
end
|
|
244
479
|
unsigned_sentences_table = TTY::Table.new(data)
|
|
245
480
|
Aromancer::Prompt.say(unsigned_sentences_table.render(:unicode))
|
|
246
481
|
end
|
|
247
482
|
|
|
248
483
|
# unspoken words
|
|
249
484
|
Aromancer::Prompt.say(I18n.t("routes.legend.unspoken_words"))
|
|
250
|
-
data = [
|
|
251
|
-
|
|
252
|
-
|
|
485
|
+
data = arena["player"]["words"].map{|w| w["value_display"]}.each_slice(wpr).to_a || []
|
|
486
|
+
while data.any? && data.last.length < data.first.length
|
|
487
|
+
data.last << ""
|
|
488
|
+
end
|
|
253
489
|
words_table = TTY::Table.new(data)
|
|
254
490
|
Aromancer::Prompt.say(words_table.render(:ascii))
|
|
255
491
|
|
|
256
|
-
unless arena["player"]["sentences"].empty?
|
|
492
|
+
unless arena["player"]["sentences"].empty?
|
|
257
493
|
# signed sentences
|
|
258
|
-
Aromancer::Prompt.say(I18n.t("routes.legend.signed_sentences"))
|
|
259
|
-
|
|
260
|
-
arena["player"]["sentences"].map{|s|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
]
|
|
268
|
-
sentences_table = TTY::Table.new(data)
|
|
269
|
-
Aromancer::Prompt.say(sentences_table.render(:ascii))
|
|
494
|
+
Aromancer::Prompt.say("#{I18n.t("routes.legend.signed_sentences")} (#{arena["player"]["sentences"].length})")
|
|
495
|
+
unless Aromancer::Storage.get_preference(:hide_sentences)
|
|
496
|
+
data = arena["player"]["sentences"].map{|s| s["value_display"]}.each_slice(wpr).to_a || []
|
|
497
|
+
while data.any? && data.last.length < data.first.length
|
|
498
|
+
data.last << ""
|
|
499
|
+
end
|
|
500
|
+
sentences_table = TTY::Table.new(data)
|
|
501
|
+
Aromancer::Prompt.say(sentences_table.render(:ascii))
|
|
502
|
+
end
|
|
270
503
|
end
|
|
271
504
|
end
|
|
272
505
|
|
|
@@ -275,140 +508,121 @@ module Aromancer
|
|
|
275
508
|
legend
|
|
276
509
|
|
|
277
510
|
arena = arena_data
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
511
|
+
Thread.main[:menu_options][__method__.to_sym] = [
|
|
512
|
+
{name: I18n.t("shared.back"), value: :back}
|
|
513
|
+
] + arena["player"]["words"].map{|w| {name: w["value_display"], value: w["id"]}}
|
|
514
|
+
|
|
515
|
+
Thread.main[:menu_runners][__method__.to_sym] = [
|
|
516
|
+
{value: :back, proc: Proc.new{ legend_menu }}
|
|
517
|
+
] + arena["player"]["words"].map{|w|
|
|
518
|
+
{value: w["id"], proc: Proc.new{
|
|
519
|
+
word(w["id"])
|
|
520
|
+
}}
|
|
521
|
+
}
|
|
522
|
+
Thread.main[:route] = __method__.to_sym
|
|
286
523
|
end
|
|
287
524
|
|
|
288
|
-
def self.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :word))
|
|
292
|
-
possibilities = Aromancer::Api.load_word_possibilities(selected_word_id)
|
|
293
|
-
|
|
294
|
-
# todo: hide/show this
|
|
295
|
-
puts JSON.pretty_generate possibilities
|
|
296
|
-
|
|
297
|
-
options = possibilities["options"]
|
|
298
|
-
selected_word = possibilities["word"]
|
|
299
|
-
for_type = possibilities["for_type"].to_sym
|
|
525
|
+
def self.spoken_words
|
|
526
|
+
cls
|
|
527
|
+
legend
|
|
300
528
|
|
|
301
529
|
arena = arena_data
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
o_value = o["sentence"]["value"]
|
|
313
|
-
o_value_display = "#{o_value} (#{I18n.t("routes.legend.sentences")})"
|
|
314
|
-
end
|
|
315
|
-
# todo: this sucks
|
|
316
|
-
# case a
|
|
317
|
-
# when :can_sign
|
|
318
|
-
# when :can_combine
|
|
319
|
-
# when :can_stack
|
|
320
|
-
# end
|
|
321
|
-
calc = "(#{sw["value"]} + #{o_value} = #{sw["value"] + o_value})"
|
|
322
|
-
|
|
323
|
-
"#{sw["value_display"]} #{a} #{o_value_display} #{calc}"
|
|
530
|
+
Thread.main[:menu_options][__method__.to_sym] = [
|
|
531
|
+
{name: I18n.t("shared.back"), value: :back}
|
|
532
|
+
] + arena["scroll_words"].map{|w| {name: w["value_display"], value: w["id"]}}
|
|
533
|
+
|
|
534
|
+
Thread.main[:menu_runners][__method__.to_sym] = [
|
|
535
|
+
{value: :back, proc: Proc.new{ legend_menu }}
|
|
536
|
+
] + arena["scroll_words"].map{|w|
|
|
537
|
+
{value: w["id"], proc: Proc.new{
|
|
538
|
+
word(w["id"])
|
|
539
|
+
}}
|
|
324
540
|
}
|
|
325
|
-
|
|
326
|
-
choices = [
|
|
327
|
-
{name: :back, value: :back}
|
|
328
|
-
]
|
|
329
|
-
if for_type == :player_word
|
|
330
|
-
# show place on scroll option if selected word is from player's words
|
|
331
|
-
choices << {name: I18n.t("routes.legend.place_on_scroll", word: selected_word["value_display"]), value: :player_word}
|
|
332
|
-
end
|
|
333
|
-
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
|
-
|
|
364
|
-
legend_menu
|
|
365
|
-
end
|
|
541
|
+
Thread.main[:route] = __method__.to_sym
|
|
366
542
|
end
|
|
367
543
|
|
|
368
|
-
def self.
|
|
544
|
+
def self.unsigned_sentences
|
|
369
545
|
cls
|
|
370
546
|
legend
|
|
371
547
|
|
|
372
548
|
arena = arena_data
|
|
373
|
-
|
|
374
|
-
|
|
549
|
+
Thread.main[:menu_options][__method__.to_sym] = [
|
|
550
|
+
{name: I18n.t("shared.back"), value: :back}
|
|
551
|
+
] + arena["sentences"].map{|s| {name: "id: #{s["id"]}, value: #{s["value"]}", value: s["id"]}}
|
|
375
552
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
553
|
+
Thread.main[:menu_runners][__method__.to_sym] = [
|
|
554
|
+
{value: :back, proc: Proc.new{ legend_menu }}
|
|
555
|
+
] + arena["sentences"].map{|s|
|
|
556
|
+
ss_words = s["words"]
|
|
557
|
+
wid = ss_words.first["id"]
|
|
379
558
|
|
|
380
|
-
|
|
559
|
+
{value: s["id"], proc: Proc.new{word(wid)}}
|
|
560
|
+
}
|
|
561
|
+
Thread.main[:route] = __method__.to_sym
|
|
381
562
|
end
|
|
382
563
|
|
|
383
|
-
def self.
|
|
384
|
-
|
|
385
|
-
legend
|
|
564
|
+
def self.word(selected_word_id)
|
|
565
|
+
return legend_menu if selected_word_id.nil?
|
|
386
566
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
selected_sentence = Aromancer::Prompt.p.select(I18n.t("routes.legend.unsigned_sentences"), choices, show_help: :always, cycle: true, per_page: 11)
|
|
567
|
+
Aromancer::Prompt.say(I18n.t("shared.navigate", route: :word)) if Aromancer::Storage.get_preference(:debug)
|
|
568
|
+
possibilities = Aromancer::Api.load_word_possibilities(selected_word_id)
|
|
390
569
|
|
|
391
|
-
if
|
|
392
|
-
|
|
570
|
+
if Aromancer::Storage.get_preference(:debug)
|
|
571
|
+
Aromancer::Prompt.say(JSON.pretty_generate(possibilities))
|
|
393
572
|
end
|
|
394
573
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
574
|
+
options = possibilities["options"]
|
|
575
|
+
selected_word = possibilities["word"]
|
|
576
|
+
for_type = possibilities["for_type"].to_sym
|
|
398
577
|
|
|
399
|
-
|
|
400
|
-
|
|
578
|
+
arena = arena_data
|
|
579
|
+
player_words = arena["player"]["words"]
|
|
401
580
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
581
|
+
choices = [{name: I18n.t("shared.back"), value: :back}]
|
|
582
|
+
if for_type == :player_word
|
|
583
|
+
|
|
584
|
+
# show place on scroll option if selected word is from player's words
|
|
585
|
+
choices << {
|
|
586
|
+
name: I18n.t("routes.legend.place_on_scroll", word: selected_word["value_display"]),
|
|
587
|
+
value: :player_word
|
|
588
|
+
}
|
|
410
589
|
end
|
|
411
|
-
end
|
|
412
590
|
|
|
591
|
+
choices += options.map{|o| {name: "#{o["humanized_title"]} -> weight: #{o["total_weight"]}", value: o}}
|
|
592
|
+
|
|
593
|
+
Thread.main[:menu_options][__method__.to_sym] = choices
|
|
594
|
+
Thread.main[:menu_runners][__method__.to_sym] = [
|
|
595
|
+
{value: :back, proc: Proc.new{
|
|
596
|
+
case for_type
|
|
597
|
+
when :player_word
|
|
598
|
+
words
|
|
599
|
+
when :scroll_word
|
|
600
|
+
spoken_words
|
|
601
|
+
when :scroll_sentence
|
|
602
|
+
unsigned_sentences
|
|
603
|
+
end
|
|
604
|
+
}},
|
|
605
|
+
{value: :player_word, proc: Proc.new{
|
|
606
|
+
wytyd = I18n.t("routes.legend.place_on_scroll", word: selected_word["value_display"])
|
|
607
|
+
Aromancer::Prompt.say(wytyd)
|
|
608
|
+
Aromancer::Api.create_turn({
|
|
609
|
+
wytyd: wytyd,
|
|
610
|
+
word_id: selected_word["id"]
|
|
611
|
+
})
|
|
612
|
+
legend_menu
|
|
613
|
+
}},
|
|
614
|
+
{value: nil, proc: Proc.new{|o|
|
|
615
|
+
if o["http_verb"] == "post"
|
|
616
|
+
Aromancer::Api.create_turn(JSON.parse(o["payload"]))
|
|
617
|
+
else
|
|
618
|
+
Aromancer::Api.update_turn(JSON.parse(o["payload"]))
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
legend_menu
|
|
622
|
+
}}
|
|
623
|
+
]
|
|
624
|
+
Thread.main[:route_params] = [selected_word_id]
|
|
625
|
+
Thread.main[:route] = __method__.to_sym
|
|
626
|
+
end
|
|
413
627
|
end
|
|
414
628
|
end
|