aromancer 0.0.6 → 0.0.8

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.
@@ -13,6 +13,8 @@
13
13
  module Aromancer
14
14
  class Routes
15
15
 
16
+ WIDTH_MULTIPLIER = TTY::Screen.width / 4.0
17
+
16
18
  def self.resume
17
19
  return main_menu if Aromancer::Storage.get_signed_out_flag
18
20
 
@@ -28,12 +30,7 @@ module Aromancer
28
30
  rescue ArgumentError => e
29
31
  authentication
30
32
  end
31
- return
32
33
  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
34
  end
38
35
 
39
36
  def self.cls
@@ -49,25 +46,10 @@ module Aromancer
49
46
  ).first
50
47
  end
51
48
 
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
64
- else
65
- arena
66
- end
67
- end
68
-
69
49
  def self.authentication
70
- if Aromancer::Storage.get_player
50
+ unless Aromancer::Storage.get_player.nil? ||
51
+ Aromancer::Storage.get_player["api_key"].nil?
52
+
71
53
  Aromancer::Storage.set_signed_out_flag(false)
72
54
  return main_menu
73
55
  end
@@ -91,6 +73,9 @@ module Aromancer
91
73
  }},
92
74
  {value: :configure, proc: Proc.new{
93
75
  configure
76
+ }},
77
+ {value: :exit, proc: Proc.new{
78
+ exit
94
79
  }}
95
80
  ]
96
81
  Thread.main[:route] = __method__.to_sym
@@ -98,7 +83,7 @@ module Aromancer
98
83
 
99
84
  def self.configure
100
85
  cls
101
-
86
+ Aromancer.print_large_text(Thread.main[:route].to_s)
102
87
  Aromancer::Prompt.say(I18n.t("routes.configure.title", name: Aromancer.to_s.downcase))
103
88
  [
104
89
  Aromancer::Storage.get_server_url,
@@ -182,6 +167,20 @@ module Aromancer
182
167
  Thread.main[:route] = __method__.to_sym
183
168
  end
184
169
 
170
+ def self.rules
171
+ return if Thread.main[:route] == __method__.to_sym
172
+ rules = Aromancer::Api.load_rules
173
+ Aromancer::Prompt.say(rules["rules"], ljust: true)
174
+
175
+ Thread.main[:menu_options][__method__.to_sym] = [
176
+ {name: I18n.t("shared.key_press"), value: :key_press}
177
+ ]
178
+ Thread.main[:menu_runners][__method__.to_sym] = [
179
+ {value: :key_press, proc: Proc.new{ main_menu }}
180
+ ]
181
+ Thread.main[:route] = __method__.to_sym
182
+ end
183
+
185
184
  def self.main_menu
186
185
  cls
187
186
  Aromancer::Prompt.say(I18n.t("shared.navigate", route: :main_menu)) if Aromancer::Storage.get_preference(:debug)
@@ -200,10 +199,12 @@ module Aromancer
200
199
 
201
200
  return authentication if player.nil?
202
201
 
202
+ Aromancer.print_large_text
203
203
  Thread.main[:menu_options][__method__.to_sym] ||= [
204
204
  {name: I18n.t("routes.main_menu.new_game"), value: :new},
205
205
  {name: I18n.t("routes.main_menu.load_game"), value: :load},
206
206
  {name: I18n.t("routes.main_menu.find_game"), value: :find},
207
+ {name: I18n.t("routes.main_menu.rules"), value: :rules},
207
208
  {name: I18n.t("routes.main_menu.configure"), value: :configure},
208
209
  {name: I18n.t("routes.main_menu.sign_out"), value: :out},
209
210
  {name: I18n.t("shared.exit"), value: :exit}
@@ -227,6 +228,9 @@ module Aromancer
227
228
  {value: :configure, proc: Proc.new{
228
229
  configure
229
230
  }},
231
+ {value: :rules, proc: Proc.new{
232
+ rules
233
+ }},
230
234
  {value: :out, proc: Proc.new{
231
235
  case Aromancer::Prompt.p.select(I18n.t("shared.confirm"), [:no, :yes], cycle: true, per_page: 11)
232
236
  when :no
@@ -235,6 +239,9 @@ module Aromancer
235
239
  Aromancer::Api.sign_out
236
240
  authentication
237
241
  end
242
+ }},
243
+ {value: :exit, proc: Proc.new{
244
+ exit
238
245
  }}
239
246
  ]
240
247
  Thread.main[:route] = __method__.to_sym
@@ -260,18 +267,8 @@ module Aromancer
260
267
  ]
261
268
  Thread.main[:menu_runners][__method__.to_sym] = [
262
269
  {value: :continue, proc: Proc.new{
263
- Aromancer::Storage.instance.clear_cache!
264
270
  Aromancer::Api.create_legend(params)
265
271
  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
272
  }},
276
273
  {value: :cancel, proc: Proc.new{
277
274
  Aromancer::Prompt.say(I18n.t("routes.new_game.cancelled"))
@@ -289,7 +286,6 @@ module Aromancer
289
286
 
290
287
  # if legend_array.nil?, load player's legends
291
288
  if legend_array.nil?
292
- Aromancer::Storage.instance.clear_cache!
293
289
  Aromancer::Api.get_legends
294
290
  legend_array = Aromancer::Storage.get_legends
295
291
  unless legend_array.any?
@@ -301,7 +297,7 @@ module Aromancer
301
297
 
302
298
  Thread.main[:menu_options][__method__.to_sym] = [{name: I18n.t("shared.back"), value: :back}] + legend_array.map{|l|
303
299
  {
304
- name: "#{I18n.t("routes.legend.title")}_#{l["id"]} (#{l["status"]}) #{DateTime.parse(l["created_at"])&.strftime(Aromancer::Api::DATE_FORMAT)}",
300
+ name: "#{l["value_display"]} > #{l["status"]} > #{Aromancer.date_display(l["created_at"])}",
305
301
  value: l["id"]
306
302
  }
307
303
  }
@@ -311,39 +307,37 @@ module Aromancer
311
307
  end
312
308
 
313
309
  Thread.main[:menu_runners][__method__.to_sym] = [
314
- {value: :back, proc: Proc.new{ main_menu }},
310
+ {value: :back, proc: Proc.new{
311
+ Aromancer::Api.set_active_legend_id(nil)
312
+ main_menu
313
+ }},
315
314
  ] + legend_array.map{|l|
316
315
  {
317
316
  value: l["id"],
318
317
  proc: Proc.new{
319
318
  Aromancer::Api.set_active_legend_id(l["id"])
319
+ sleep(1)
320
+ Aromancer::Api.get_legends
320
321
 
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
322
+ legend_menu
328
323
  }
329
324
  }
330
325
  }
331
326
  Thread.main[:route] = __method__.to_sym
332
327
  end
333
328
 
334
- def self.stream
335
- Aromancer::Api.load_stream
329
+ def self.stream(display_only: false, recent_count: nil)
330
+ return if Thread.main[:route] == __method__.to_sym
331
+ Aromancer::Prompt.print_divider(I18n.t("routes.stream.title"))
332
+ Aromancer::Api.load_stream(recent_count)
336
333
  stream = Aromancer::Storage.get_stream
337
- Aromancer::Prompt.say(I18n.t("routes.stream.title"))
338
- Aromancer::Prompt.say([
339
- :timestamp,
340
- :description
341
- ].join(", "))
342
-
343
- stream["stream"].each{|e|
344
- Aromancer::Prompt.say("\n")
345
- Aromancer::Prompt.say([e["updated_at"], e["description"]].join("\n"))
334
+ stream["stream"].last(
335
+ recent_count.nil? ? stream["stream"].count : recent_count
336
+ ).each{|e|
337
+ Aromancer::Prompt.say("[#{Aromancer.time_display(e["updated_at"])}]: #{e["description"]}", ljust: true)
346
338
  }
339
+ Aromancer::Prompt.print_divider(I18n.t("routes.stream.end"))
340
+ return if display_only
347
341
 
348
342
  Thread.main[:menu_options][__method__.to_sym] ||= [{name: I18n.t("shared.key_press"), value: nil}]
349
343
  Thread.main[:menu_runners][__method__.to_sym] ||= [
@@ -354,52 +348,93 @@ module Aromancer
354
348
 
355
349
  def self.legend_menu
356
350
  cls
357
- legend
358
-
359
- legend_array = Aromancer::Storage.get_legends
360
351
  al = active_legend
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"
352
+ al_status = ((al || {})["status"] || "").to_sym
353
+ arena = Aromancer::Storage.get_arena
354
+ if !al_status.nil? &&
355
+ ![:started, :paused].include?(al_status) &&
356
+ !al.nil? &&
357
+ !arena.nil?
358
+
359
+ stream(display_only: true) # display entire stream
360
+ Aromancer::Prompt.print_divider(al["value_display"])
361
+ Aromancer::Prompt.say(arena["title"])
362
+ Aromancer::Prompt.say(arena["players"].map{|p| "#{p["alias"]}(#{p["status"]}): #{p["score"]}"}.join(" | "))
363
+ Thread.main[:route] = __method__.to_sym
364
+ case al_status
365
+ when :created
366
+ Aromancer::Api.get_legends
367
+
368
+ Thread.main[:menu_options][__method__.to_sym] = [
369
+ {name: I18n.t("shared.key_press"), value: :key_press}
370
+ ]
371
+ Thread.main[:menu_runners][__method__.to_sym] = [
372
+ {value: :key_press, proc: Proc.new{
373
+ Aromancer::Prompt.say(I18n.t("routes.legend.returning_to_", route: :legends))
374
+ Aromancer::Api.set_active_legend_id(nil)
375
+ sleep(1)
376
+ legends
377
+ }}
378
+ ]
379
+ when :complete
367
380
  Thread.main[:menu_options][__method__.to_sym] = [
368
- {name: :reload, value: :reload}, {name: I18n.t("shared.back"), value: :back}
381
+ {name: I18n.t("shared.key_press"), value: :key_press}
369
382
  ]
370
- Thread.main[:menu_runners][__method__.to_sym] ||= [
371
- {value: :reload, proc: Proc.new{ legend_menu }},
372
- {value: :back, proc: Proc.new{
383
+ Thread.main[:menu_runners][__method__.to_sym] = [
384
+ {value: :key_press, proc: Proc.new{
385
+ Aromancer::Prompt.say(I18n.t("routes.legend.returning_to_", route: :legends))
373
386
  Aromancer::Api.set_active_legend_id(nil)
374
- main_menu
387
+ legends
375
388
  }}
376
389
  ]
377
- Thread.main[:route] = __method__.to_sym
378
- return
379
390
  end
391
+ return
392
+ end
393
+
394
+ arena = Aromancer::Storage.get_arena
395
+ if arena.nil? || arena["turn_player"].nil?
396
+ Aromancer::Prompt.say(I18n.t("shared.waiting"))
397
+ Thread.main[:menu_options][__method__.to_sym] = []
398
+ Thread.main[:menu_runners][__method__.to_sym] = []
399
+ sleep(1)
400
+ Aromancer::Api.get_legends
401
+ Aromancer::Api.load_arena
402
+ return
380
403
  end
381
- hs = Aromancer::Storage.get_preference(:hide_sentences)
382
- hs_value = "#{hs ? "" : "hide_"}signed_sentences".to_sym
404
+
405
+ legend
383
406
 
384
407
  Thread.main[:route] = __method__.to_sym
408
+
409
+ hide_sentences_pref = Aromancer::Storage.get_preference(:hide_sentences)
410
+ hide_sentences_pref_value = "#{hide_sentences_pref ? "" : "hide_"}signed_sentences".to_sym
411
+ hide_stream_pref = Aromancer::Storage.get_preference(:hide_stream)
412
+ hide_stream_pref_value = "#{hide_stream_pref ? "" : "hide_"}title".to_sym
385
413
  Thread.main[:menu_options][__method__.to_sym] = [
386
- {name: I18n.t("routes.legend.unspoken_words"), value: :words},
387
- {name: I18n.t("routes.legend.spoken_words"), value: :spoken_words},
388
- {name: I18n.t("routes.legend.unsigned_sentences"), value: :unsigned_sentences},
389
- {name: I18n.t("routes.legend.#{hs_value}"), value: hs_value},
390
- {name: I18n.t("routes.stream.title"), value: :stream},
414
+ {name: I18n.t("routes.legend.#{hide_sentences_pref_value}"), value: hide_sentences_pref_value},
415
+ {name: I18n.t("routes.stream.#{hide_stream_pref_value}"), value: hide_stream_pref_value},
391
416
  {name: I18n.t("routes.main_menu.title"), value: :main_menu}
392
417
  ]
418
+ if arena["turn_player"]["id"] == Aromancer::Storage.get_player["id"]
419
+ [
420
+ {name: I18n.t("routes.legend.unspoken_words"), value: :words},
421
+ {name: I18n.t("routes.legend.spoken_words"), value: :spoken_words},
422
+ {name: I18n.t("routes.legend.unsigned_sentences"), value: :unsigned_sentences}
423
+ ].reverse.each{|mo| Thread.main[:menu_options][__method__.to_sym].insert(0, mo)}
424
+ end
393
425
 
394
426
  Thread.main[:menu_runners][__method__.to_sym] = [
395
427
  {value: :words, proc: Proc.new{ words }},
396
428
  {value: :spoken_words, proc: Proc.new{ spoken_words }},
397
429
  {value: :unsigned_sentences, proc: Proc.new{ unsigned_sentences }},
398
- {value: hs_value, proc: Proc.new{
430
+ {value: hide_sentences_pref_value, proc: Proc.new{
399
431
  Aromancer::Storage.toggle_preference(:hide_sentences)
400
432
  legend_menu
401
433
  }},
402
- {value: :stream, proc: Proc.new{ stream }},
434
+ {value: hide_stream_pref_value, proc: Proc.new{
435
+ Aromancer::Storage.toggle_preference(:hide_stream)
436
+ legend_menu
437
+ }},
403
438
  {value: :main_menu, proc: Proc.new{
404
439
  Aromancer::Api.set_active_legend_id(nil)
405
440
  main_menu
@@ -409,60 +444,34 @@ module Aromancer
409
444
 
410
445
  def self.legend
411
446
  Aromancer::Prompt.say(I18n.t("shared.navigate", route: :legend)) if Aromancer::Storage.get_preference(:debug)
412
- Aromancer::Api.load_arena
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
-
447
+ arena = Aromancer::Storage.get_arena
434
448
  return if arena.nil? || arena["turn_player"].nil?
435
449
 
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
442
-
443
450
  turn_player = arena["turn_player"]
444
451
 
445
452
  # title
446
- Aromancer::Prompt.say("\n\n")
447
- data = [
448
- [arena["title"]],
449
- ["#{turn_player["alias"]}'s turn"],
450
- ["dealer is #{arena["dealer"]["alias"]}"]
451
- ]
452
- title_table = TTY::Table.new(data)
453
- Aromancer::Prompt.say(title_table.render(:ascii))
454
-
455
- # players
456
- data = [
457
- [I18n.t("routes.legend.players")] + arena["players"].map{|p| "#{p["alias"]} (#{p["score"]})"}
458
- ]
459
- players_table = TTY::Table.new(data)
460
- Aromancer::Prompt.say(players_table.render(:ascii))
453
+ Aromancer::Prompt.say("\n")
454
+ ([
455
+ "#{I18n.t("routes.legend.title")}: #{(active_legend || {})["value_display"]}",
456
+ "#{arena["title"]}: #{turn_player["alias"]}'s turn. dealer is #{arena["dealer"]["alias"]}"
457
+ ] + arena["players"].map{|p| "#{p["alias"].rjust(11)} (#{p["score"]})"}
458
+ ).each{|l| Aromancer::Prompt.say(l, rjust: true)}
459
+
460
+ if !arena["bot_player"].nil?
461
+ # todo: show/hide preference
462
+ render_alchemy_for(arena["bot_player"])
463
+ end
464
+ render_scroll(arena)
465
+ render_alchemy_for(arena["player"])
466
+ end
461
467
 
468
+ # todo: move this to helper class. not a route
469
+ def self.render_scroll(arena)
470
+ Aromancer::Prompt.print_divider(I18n.t("routes.legend.scroll"))
462
471
  # spoken words
463
472
  Aromancer::Prompt.say(I18n.t("routes.legend.spoken_words"))
464
-
465
- data = arena["scroll_words"].map{|sw| sw["value_display"]}.each_slice(wpr).to_a || []
473
+ Aromancer::Prompt.say("\n")
474
+ data = arena["scroll_words"].map{|sw| sw["value_display"]}.each_slice(Aromancer::Routes::WIDTH_MULTIPLIER).to_a || []
466
475
  while data.any? && data.last.length < data.first.length
467
476
  data.last << ""
468
477
  end
@@ -472,34 +481,52 @@ module Aromancer
472
481
  unless arena["sentences"].empty?
473
482
  # unsigned sentences
474
483
  Aromancer::Prompt.say(I18n.t("routes.legend.unsigned_sentences"))
475
- data = arena["sentences"].map{|sw| sw["value_display"]}.each_slice(wpr).to_a || []
484
+ Aromancer::Prompt.say("\n")
485
+ data = arena["sentences"].map{|sw| sw["value_display"]}.each_slice(Aromancer::Routes::WIDTH_MULTIPLIER).to_a || []
476
486
  while data.any? && data.last.length < data.first.length
477
487
  data.last << ""
478
488
  end
479
489
  unsigned_sentences_table = TTY::Table.new(data)
480
- Aromancer::Prompt.say(unsigned_sentences_table.render(:unicode))
490
+ Aromancer::Prompt.say(unsigned_sentences_table.render)
481
491
  end
492
+ end
482
493
 
494
+ # todo: move this to helper class. not a route
495
+ def self.render_alchemy_for(player)
483
496
  # unspoken words
497
+ if player["id"].to_i != Aromancer::Storage.get_player["id"].to_i
498
+ Aromancer::Prompt.print_divider(I18n.t("routes.legend.alchemy_for", name: player["alias"]))
499
+ else
500
+ Aromancer::Prompt.print_divider(I18n.t("routes.legend.your_alchemy"))
501
+ end
484
502
  Aromancer::Prompt.say(I18n.t("routes.legend.unspoken_words"))
485
- data = arena["player"]["words"].map{|w| w["value_display"]}.each_slice(wpr).to_a || []
503
+ Aromancer::Prompt.say("\n\n")
504
+ words = player["words"].map{|w| w["value_display"]}
505
+ data = words.each_slice(Aromancer::Routes::WIDTH_MULTIPLIER).to_a || []
486
506
  while data.any? && data.last.length < data.first.length
487
507
  data.last << ""
488
508
  end
489
509
  words_table = TTY::Table.new(data)
490
510
  Aromancer::Prompt.say(words_table.render(:ascii))
491
511
 
492
- unless arena["player"]["sentences"].empty?
512
+ unless player["sentences"].empty?
493
513
  # signed sentences
494
- Aromancer::Prompt.say("#{I18n.t("routes.legend.signed_sentences")} (#{arena["player"]["sentences"].length})")
514
+ Aromancer::Prompt.say("#{I18n.t("routes.legend.signed_sentences")} (#{player["sentences"].length})")
495
515
  unless Aromancer::Storage.get_preference(:hide_sentences)
496
- data = arena["player"]["sentences"].map{|s| s["value_display"]}.each_slice(wpr).to_a || []
516
+ data = player["sentences"].map{|s| s["value_display"]}.each_slice(Aromancer::Routes::WIDTH_MULTIPLIER).to_a || []
497
517
  while data.any? && data.last.length < data.first.length
498
518
  data.last << ""
499
519
  end
500
520
  sentences_table = TTY::Table.new(data)
501
- Aromancer::Prompt.say(sentences_table.render(:ascii))
521
+ Aromancer::Prompt.say(sentences_table.render)
502
522
  end
523
+ Aromancer::Prompt.say("\n\n")
524
+ end
525
+
526
+ unless player["id"].to_i != Aromancer::Storage.get_player["id"].to_i ||
527
+ Aromancer::Storage.get_preference(:hide_stream)
528
+
529
+ stream(display_only: true, recent_count: 5)
503
530
  end
504
531
  end
505
532
 
@@ -507,7 +534,12 @@ module Aromancer
507
534
  cls
508
535
  legend
509
536
 
510
- arena = arena_data
537
+ arena = Aromancer::Storage.get_arena
538
+ if arena["player"].nil? || arena["player"]["words"].nil?
539
+ Aromancer::Api.load_arena
540
+ sleep(1)
541
+ main_menu
542
+ end
511
543
  Thread.main[:menu_options][__method__.to_sym] = [
512
544
  {name: I18n.t("shared.back"), value: :back}
513
545
  ] + arena["player"]["words"].map{|w| {name: w["value_display"], value: w["id"]}}
@@ -526,7 +558,7 @@ module Aromancer
526
558
  cls
527
559
  legend
528
560
 
529
- arena = arena_data
561
+ arena = Aromancer::Storage.get_arena
530
562
  Thread.main[:menu_options][__method__.to_sym] = [
531
563
  {name: I18n.t("shared.back"), value: :back}
532
564
  ] + arena["scroll_words"].map{|w| {name: w["value_display"], value: w["id"]}}
@@ -545,10 +577,10 @@ module Aromancer
545
577
  cls
546
578
  legend
547
579
 
548
- arena = arena_data
580
+ arena = Aromancer::Storage.get_arena
549
581
  Thread.main[:menu_options][__method__.to_sym] = [
550
582
  {name: I18n.t("shared.back"), value: :back}
551
- ] + arena["sentences"].map{|s| {name: "id: #{s["id"]}, value: #{s["value"]}", value: s["id"]}}
583
+ ] + arena["sentences"].map{|s| {name: s["value_display"], value: s["id"]}}
552
584
 
553
585
  Thread.main[:menu_runners][__method__.to_sym] = [
554
586
  {value: :back, proc: Proc.new{ legend_menu }}
@@ -566,7 +598,7 @@ module Aromancer
566
598
 
567
599
  Aromancer::Prompt.say(I18n.t("shared.navigate", route: :word)) if Aromancer::Storage.get_preference(:debug)
568
600
  possibilities = Aromancer::Api.load_word_possibilities(selected_word_id)
569
-
601
+ request_uuid = possibilities["uuid"]
570
602
  if Aromancer::Storage.get_preference(:debug)
571
603
  Aromancer::Prompt.say(JSON.pretty_generate(possibilities))
572
604
  end
@@ -575,11 +607,12 @@ module Aromancer
575
607
  selected_word = possibilities["word"]
576
608
  for_type = possibilities["for_type"].to_sym
577
609
 
578
- arena = arena_data
610
+ arena = Aromancer::Storage.get_arena
579
611
  player_words = arena["player"]["words"]
580
612
 
581
613
  choices = [{name: I18n.t("shared.back"), value: :back}]
582
- if for_type == :player_word
614
+ if for_type == :player_word &&
615
+ arena["turn_player"]["id"] == Aromancer::Storage.get_player["id"]
583
616
 
584
617
  # show place on scroll option if selected word is from player's words
585
618
  choices << {
@@ -588,8 +621,11 @@ module Aromancer
588
621
  }
589
622
  end
590
623
 
591
- choices += options.map{|o| {name: "#{o["humanized_title"]} -> weight: #{o["total_weight"]}", value: o}}
624
+ unless arena["turn_player"]["id"] != Aromancer::Storage.get_player["id"]
625
+ choices += options.map{|o| {name: "#{o["humanized_title"]} -> weight: #{o["total_weight"]}", value: o}}
626
+ end
592
627
 
628
+ _muh_method = __method__.to_sym
593
629
  Thread.main[:menu_options][__method__.to_sym] = choices
594
630
  Thread.main[:menu_runners][__method__.to_sym] = [
595
631
  {value: :back, proc: Proc.new{
@@ -603,22 +639,24 @@ module Aromancer
603
639
  end
604
640
  }},
605
641
  {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
642
+ Aromancer::Prompt.say(I18n.t("shared.waiting"))
643
+ Thread.main[:menu_options][_muh_method] = []
644
+ Thread.main[:menu_runners][_muh_method] = []
645
+ Aromancer::Api.submit_turn(request_uuid)
646
+ # websockets will trigger this for other player after turn is submitted
647
+ Aromancer::Api.get_legends
648
+ Aromancer::Api.load_arena
649
+ sleep(1)
613
650
  }},
614
651
  {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
652
+ Aromancer::Prompt.say(I18n.t("shared.waiting"))
653
+ Thread.main[:menu_options][_muh_method] = []
654
+ Thread.main[:menu_runners][_muh_method] = []
655
+ Aromancer::Api.submit_turn(request_uuid, {option_uuid: o[:uuid.to_s]})
656
+ # websockets will trigger this for other player after turn is submitted
657
+ Aromancer::Api.get_legends
658
+ Aromancer::Api.load_arena
659
+ sleep(1)
622
660
  }}
623
661
  ]
624
662
  Thread.main[:route_params] = [selected_word_id]
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+
5
+ serve.rb
6
+
7
+ aromancer serve functionality.
8
+
9
+ by i2097i
10
+
11
+ =end
12
+
13
+ module Aromancer
14
+ class Serve
15
+ SERVER_NAME = :"#{Aromancer.to_s.downcase}_serve".to_s
16
+
17
+ def self.run
18
+ unless Dir.exist?(serve_dir)
19
+ system(:"git clone git@github.com:arowmancy/#{SERVER_NAME}.git #{serve_dir}".to_s)
20
+ end
21
+ FileUtils.chdir serve_dir do
22
+ branch = "v#{Aromancer::VERSION}"
23
+ system(:"git checkout #{branch}".to_s)
24
+ system(:"git pull origin #{branch}".to_s)
25
+ system(:"bin/setup".to_s)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def self.serve_dir
32
+ File.join(Aromancer.home_directory, SERVER_NAME)
33
+ end
34
+ end
35
+ end
@@ -22,7 +22,6 @@ module Aromancer
22
22
  def initialize(status: -1, body: {})
23
23
  @status = status
24
24
  @body = body
25
- Aromancer::Storage.instance.clear_cache!
26
25
  end
27
26
 
28
27
  def self.build(e)
@@ -141,7 +140,7 @@ module Aromancer
141
140
  end
142
141
  end
143
142
 
144
- def self.get_stream
143
+ def self.get_stream(count = nil)
145
144
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
146
145
  return InternalError.build(StandardError.new("no active legend")) if legend_id.nil?
147
146
 
@@ -149,7 +148,7 @@ module Aromancer
149
148
  Faraday.new(
150
149
  url: Aromancer::Storage.get_server_url,
151
150
  headers: HEADERS.merge(auth_header),
152
- ).get("/legends/#{legend_id}/stream")
151
+ ).get("/legends/#{legend_id}/stream?count=#{count || nil}")
153
152
  rescue StandardError => e
154
153
  InternalError.build(e)
155
154
  end
@@ -169,7 +168,7 @@ module Aromancer
169
168
  end
170
169
  end
171
170
 
172
- def self.create_turn(params)
171
+ def self.submit_turn(request_uuid, params = {})
173
172
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
174
173
  return InternalError.build(StandardError.new("no active legend")) if legend_id.nil?
175
174
 
@@ -178,22 +177,18 @@ module Aromancer
178
177
  url: Aromancer::Storage.get_server_url,
179
178
  headers: HEADERS.merge(auth_header),
180
179
  params: params
181
- ).post("/legends/#{legend_id}/arena")
180
+ ).put("/legends/#{legend_id}/arena/#{request_uuid}")
182
181
  rescue StandardError => e
183
182
  InternalError.build(e)
184
183
  end
185
184
  end
186
185
 
187
- def self.update_turn(params)
188
- legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
189
- return InternalError.build(StandardError.new("no active legend")) if legend_id.nil?
190
-
186
+ def self.load_rules
191
187
  begin
192
188
  Faraday.new(
193
189
  url: Aromancer::Storage.get_server_url,
194
190
  headers: HEADERS.merge(auth_header),
195
- params: params
196
- ).put("/legends/#{legend_id}/arena")
191
+ ).get("/")
197
192
  rescue StandardError => e
198
193
  InternalError.build(e)
199
194
  end