aromancer 0.0.7 → 0.0.9

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.
@@ -46,24 +46,10 @@ module Aromancer
46
46
  ).first
47
47
  end
48
48
 
49
- def self.arena_data
50
- arena = Aromancer::Storage.get_arena
51
- if arena.nil?
52
- Aromancer::Api.load_arena
53
- sleep(1)
54
- end
55
-
56
- if arena.nil?
57
- Aromancer.print_last_error("routes.legend.arena_failed")
58
- Aromancer::Prompt.p.ask(I18n.t("shared.key_press"))
59
- Aromancer::Api.set_active_legend_id(nil)
60
- else
61
- arena
62
- end
63
- end
64
-
65
49
  def self.authentication
66
- if Aromancer::Storage.get_player
50
+ unless Aromancer::Storage.get_player.nil? ||
51
+ Aromancer::Storage.get_player["api_key"].nil?
52
+
67
53
  Aromancer::Storage.set_signed_out_flag(false)
68
54
  return main_menu
69
55
  end
@@ -87,6 +73,9 @@ module Aromancer
87
73
  }},
88
74
  {value: :configure, proc: Proc.new{
89
75
  configure
76
+ }},
77
+ {value: :exit, proc: Proc.new{
78
+ exit
90
79
  }}
91
80
  ]
92
81
  Thread.main[:route] = __method__.to_sym
@@ -94,7 +83,7 @@ module Aromancer
94
83
 
95
84
  def self.configure
96
85
  cls
97
-
86
+ Aromancer.print_large_text(Thread.main[:route].to_s)
98
87
  Aromancer::Prompt.say(I18n.t("routes.configure.title", name: Aromancer.to_s.downcase))
99
88
  [
100
89
  Aromancer::Storage.get_server_url,
@@ -133,7 +122,7 @@ module Aromancer
133
122
  Aromancer::Storage.instance.set_key(storage_key, previous)
134
123
  end
135
124
 
136
- Aromancer::Storage.instance.clear_cache!
125
+ Aromancer::Cli.instance.should_clear_cache = true
137
126
  end
138
127
  Aromancer::Prompt.say(I18n.t("shared.server_url", url: Aromancer::Storage.get_server_url))
139
128
  }
@@ -162,7 +151,7 @@ module Aromancer
162
151
  Aromancer::Prompt.say(
163
152
  I18n.t("routes.configure.force_ssl_toggle", value: Aromancer::Storage.get_preference(:force_ssl))
164
153
  )
165
- sleep(2)
154
+ sleep(1)
166
155
  configure
167
156
  }},
168
157
  {value: :debug, proc: Proc.new{
@@ -171,7 +160,7 @@ module Aromancer
171
160
  Aromancer::Prompt.say(
172
161
  I18n.t("routes.configure.debug_toggle", value: Aromancer::Storage.get_preference(:debug))
173
162
  )
174
- sleep(2)
163
+ sleep(1)
175
164
  configure
176
165
  }},
177
166
  ]
@@ -210,6 +199,7 @@ module Aromancer
210
199
 
211
200
  return authentication if player.nil?
212
201
 
202
+ Aromancer.print_large_text
213
203
  Thread.main[:menu_options][__method__.to_sym] ||= [
214
204
  {name: I18n.t("routes.main_menu.new_game"), value: :new},
215
205
  {name: I18n.t("routes.main_menu.load_game"), value: :load},
@@ -233,8 +223,8 @@ module Aromancer
233
223
  Thread.main[:route_params] = [params]
234
224
  new_game(params)
235
225
  }},
236
- {value: :load, proc: Proc.new{ Aromancer::Routes::legends }},
237
- {value: :find, proc: Proc.new{ Aromancer::Routes::find_game }},
226
+ {value: :load, proc: Proc.new{ Thread.main[:route] = :legends }},
227
+ {value: :find, proc: Proc.new{ Thread.main[:route] = :find_game }},
238
228
  {value: :configure, proc: Proc.new{
239
229
  configure
240
230
  }},
@@ -252,7 +242,7 @@ module Aromancer
252
242
  }},
253
243
  {value: :exit, proc: Proc.new{
254
244
  exit
255
- }},
245
+ }}
256
246
  ]
257
247
  Thread.main[:route] = __method__.to_sym
258
248
  end
@@ -277,22 +267,12 @@ module Aromancer
277
267
  ]
278
268
  Thread.main[:menu_runners][__method__.to_sym] = [
279
269
  {value: :continue, proc: Proc.new{
280
- Aromancer::Storage.instance.clear_cache!
281
270
  Aromancer::Api.create_legend(params)
282
- legend_menu
283
- # Aromancer::Api.get_legends
284
-
285
- # unless active_legend.nil? || active_legend["id"] != Aromancer::Storage.get_player["active_legend_id"]
286
- # Aromancer.print_last_error
287
- # sleep(1)
288
- # main_menu
289
- # else
290
- # legend_menu
291
- # end
271
+ Thread.main[:route] = :legend_menu
292
272
  }},
293
273
  {value: :cancel, proc: Proc.new{
294
274
  Aromancer::Prompt.say(I18n.t("routes.new_game.cancelled"))
295
- main_menu
275
+ Thread.main[:route] = :main_menu
296
276
  }}
297
277
  ]
298
278
  Thread.main[:route] = __method__.to_sym
@@ -306,13 +286,13 @@ module Aromancer
306
286
 
307
287
  # if legend_array.nil?, load player's legends
308
288
  if legend_array.nil?
309
- Aromancer::Storage.instance.clear_cache!
310
289
  Aromancer::Api.get_legends
311
- legend_array = Aromancer::Storage.get_legends
290
+ sleep(Aromancer::Cli::RENDER_DELAY)
291
+ legend_array = Aromancer::Storage.get_legends || []
312
292
  unless legend_array.any?
313
293
  Aromancer::Prompt.say(I18n.t("shared.empty"))
314
294
  sleep(1)
315
- return main_menu
295
+ Thread.main[:route] = :main_menu
316
296
  end
317
297
  end
318
298
 
@@ -328,20 +308,19 @@ module Aromancer
328
308
  end
329
309
 
330
310
  Thread.main[:menu_runners][__method__.to_sym] = [
331
- {value: :back, proc: Proc.new{ main_menu }},
311
+ {value: :back, proc: Proc.new{
312
+ Aromancer::Api.set_active_legend_id(nil)
313
+ Thread.main[:route] = :main_menu
314
+ }},
332
315
  ] + legend_array.map{|l|
333
316
  {
334
317
  value: l["id"],
335
318
  proc: Proc.new{
336
319
  Aromancer::Api.set_active_legend_id(l["id"])
320
+ sleep(Aromancer::Cli::RENDER_DELAY)
321
+ Aromancer::Api.get_legends
337
322
 
338
- unless active_legend.nil? || active_legend["id"] != Aromancer::Storage.get_player["active_legend_id"]
339
- Aromancer.print_last_error
340
- sleep(1)
341
- main_menu
342
- else
343
- legend_menu
344
- end
323
+ Thread.main[:route] = :legend_menu
345
324
  }
346
325
  }
347
326
  }
@@ -352,9 +331,9 @@ module Aromancer
352
331
  return if Thread.main[:route] == __method__.to_sym
353
332
  Aromancer::Prompt.print_divider(I18n.t("routes.stream.title"))
354
333
  Aromancer::Api.load_stream(recent_count)
355
- stream = Aromancer::Storage.get_stream
356
- stream["stream"].last(
357
- recent_count.nil? ? stream["stream"].count : recent_count
334
+ entries = Aromancer::Storage.get_stream
335
+ entries["stream"].last(
336
+ recent_count.nil? ? entries["stream"].count : recent_count
358
337
  ).each{|e|
359
338
  Aromancer::Prompt.say("[#{Aromancer.time_display(e["updated_at"])}]: #{e["description"]}", ljust: true)
360
339
  }
@@ -370,61 +349,82 @@ module Aromancer
370
349
 
371
350
  def self.legend_menu
372
351
  cls
373
- legend
374
-
375
- legend_array = Aromancer::Storage.get_legends
376
352
  al = active_legend
377
- if !al.nil?
378
- if al["status"] == "complete"
353
+ al_status = ((al || {})["status"] || "").to_sym
354
+ arena = Aromancer::Storage.get_arena
355
+ if !al_status.nil? &&
356
+ ![:started, :paused].include?(al_status) &&
357
+ !al.nil? &&
358
+ !arena.nil?
359
+
360
+ stream(display_only: true) # display entire stream
361
+ Aromancer::Prompt.print_divider(al["value_display"])
362
+ Aromancer::Prompt.say(arena["title"])
363
+ Aromancer::Prompt.say(arena["players"].map{|p| "#{p["alias"]}(#{p["status"]}): #{p["score"]}"}.join(" | "))
364
+ Thread.main[:route] = __method__.to_sym
365
+ case al_status
366
+ when :created
367
+ if al["player_count"] == 2
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(Aromancer::Cli::RENDER_DELAY)
376
+ Thread.main[:route] = :legends
377
+ }}
378
+ ]
379
+ Aromancer::Api.get_legends
380
+ Aromancer::Api.load_arena
381
+ end
382
+ when :complete
379
383
  Thread.main[:menu_options][__method__.to_sym] = [
380
384
  {name: I18n.t("shared.key_press"), value: :key_press}
381
385
  ]
382
386
  Thread.main[:menu_runners][__method__.to_sym] = [
383
387
  {value: :key_press, proc: Proc.new{
384
- Aromancer::Prompt.say(I18n.t("routes.legend.returning_to_main"))
388
+ Aromancer::Prompt.say(I18n.t("routes.legend.returning_to_", route: :legends))
385
389
  Aromancer::Api.set_active_legend_id(nil)
386
- legends
390
+ Thread.main[:route] = :legends
387
391
  }}
388
392
  ]
389
- Thread.main[:route] = __method__.to_sym
390
- return
391
- elsif al["status"] == "created"
392
- Thread.main[:menu_options][__method__.to_sym] = [
393
- {name: :reload, value: :reload}, {name: I18n.t("shared.back"), value: :back}
394
- ]
395
- Thread.main[:menu_runners][__method__.to_sym] = [
396
- {value: :reload, proc: Proc.new{ legend_menu }},
397
- {value: :back, proc: Proc.new{
398
- Aromancer::Api.set_active_legend_id(nil)
399
- legends
400
- }}
401
- ]
402
- Thread.main[:route] = __method__.to_sym
403
- return
404
- elsif active_legend["player"] && (active_legend["player"]["words"] || []).count == 0
405
- Aromancer::Api.load_arena
406
- return
407
393
  end
408
- else
409
- Thread.main[:menu_runners] = {}
410
- Thread.main[:menu_options] = {}
411
- Thread.main[:route] = :main_menu
394
+ return
395
+ end
396
+
397
+ arena = Aromancer::Storage.get_arena
398
+ if arena.nil? || arena["turn_player"].nil?
399
+ Aromancer::Prompt.say(I18n.t("shared.spelling"))
400
+ Thread.main[:menu_options][__method__.to_sym] = []
401
+ Thread.main[:menu_runners][__method__.to_sym] = []
402
+ sleep(Aromancer::Cli::RENDER_DELAY)
403
+ Aromancer::Api.get_legends
404
+ Aromancer::Api.load_arena
405
+ return
412
406
  end
413
407
 
408
+ legend
409
+
410
+ Thread.main[:route] = __method__.to_sym
411
+
414
412
  hide_sentences_pref = Aromancer::Storage.get_preference(:hide_sentences)
415
413
  hide_sentences_pref_value = "#{hide_sentences_pref ? "" : "hide_"}signed_sentences".to_sym
416
414
  hide_stream_pref = Aromancer::Storage.get_preference(:hide_stream)
417
415
  hide_stream_pref_value = "#{hide_stream_pref ? "" : "hide_"}title".to_sym
418
-
419
- Thread.main[:route] = __method__.to_sym
420
416
  Thread.main[:menu_options][__method__.to_sym] = [
421
- {name: I18n.t("routes.legend.unspoken_words"), value: :words},
422
- {name: I18n.t("routes.legend.spoken_words"), value: :spoken_words},
423
- {name: I18n.t("routes.legend.unsigned_sentences"), value: :unsigned_sentences},
424
417
  {name: I18n.t("routes.legend.#{hide_sentences_pref_value}"), value: hide_sentences_pref_value},
425
418
  {name: I18n.t("routes.stream.#{hide_stream_pref_value}"), value: hide_stream_pref_value},
426
419
  {name: I18n.t("routes.main_menu.title"), value: :main_menu}
427
420
  ]
421
+ if arena["turn_player"]["id"] == Aromancer::Storage.get_player["id"]
422
+ [
423
+ {name: I18n.t("routes.legend.unspoken_words"), value: :words},
424
+ {name: I18n.t("routes.legend.spoken_words"), value: :spoken_words},
425
+ {name: I18n.t("routes.legend.unsigned_sentences"), value: :unsigned_sentences}
426
+ ].reverse.each{|mo| Thread.main[:menu_options][__method__.to_sym].insert(0, mo)}
427
+ end
428
428
 
429
429
  Thread.main[:menu_runners][__method__.to_sym] = [
430
430
  {value: :words, proc: Proc.new{ words }},
@@ -447,48 +447,7 @@ module Aromancer
447
447
 
448
448
  def self.legend
449
449
  Aromancer::Prompt.say(I18n.t("shared.navigate", route: :legend)) if Aromancer::Storage.get_preference(:debug)
450
- Aromancer::Api.load_arena
451
- arena = arena_data
452
- al = active_legend
453
- al_status = ((al || {})["status"] || "").to_sym
454
- if !al.nil? &&
455
- [:created, :complete].include?(al_status)
456
-
457
- stream(display_only: true) # display entire stream
458
- Aromancer::Prompt.print_divider(al["value_display"])
459
- Aromancer::Prompt.say(arena["title"])
460
- Aromancer::Prompt.say(arena["players"].map{|p| "#{p["alias"]}(#{p["score"]})"}.join(" | "))
461
-
462
- if al_status == :complete
463
- Thread.main[:menu_options][:legend_menu] = [
464
- {name: I18n.t("shared.key_press"), value: :key_press}
465
- ]
466
- Thread.main[:menu_runners][:legend_menu] = [
467
- {value: :key_press, proc: Proc.new{
468
- Aromancer::Prompt.say(I18n.t("routes.legend.returning_to_main"))
469
- Aromancer::Api.set_active_legend_id(nil)
470
- legends
471
- }}
472
- ]
473
- else
474
- Aromancer::Api.get_legends
475
-
476
- Thread.main[:menu_options][:legend_menu] = [
477
- {name: I18n.t("shared.back"), value: :back},
478
- {name: I18n.t("shared.key_press"), value: :key_press}
479
- ]
480
- Thread.main[:menu_runners][:legend_menu] = [
481
- {value: :back, proc: Proc.new{
482
- Aromancer::Prompt.say(I18n.t("routes.legend.returning_to_main"))
483
- Aromancer::Api.set_active_legend_id(nil)
484
- legends
485
- }},
486
- {value: :key_press, proc: Proc.new{ legend_menu }}
487
- ]
488
- end
489
- return
490
- end
491
-
450
+ arena = Aromancer::Storage.get_arena
492
451
  return if arena.nil? || arena["turn_player"].nil?
493
452
 
494
453
  turn_player = arena["turn_player"]
@@ -578,7 +537,15 @@ module Aromancer
578
537
  cls
579
538
  legend
580
539
 
581
- arena = arena_data
540
+ arena = Aromancer::Storage.get_arena
541
+ if arena.nil? ||
542
+ arena["player"].nil? ||
543
+ arena["player"]["words"].nil?
544
+ sleep(Aromancer::Cli::RENDER_DELAY)
545
+
546
+ Aromancer::Api.load_arena
547
+ return
548
+ end
582
549
  Thread.main[:menu_options][__method__.to_sym] = [
583
550
  {name: I18n.t("shared.back"), value: :back}
584
551
  ] + arena["player"]["words"].map{|w| {name: w["value_display"], value: w["id"]}}
@@ -597,7 +564,7 @@ module Aromancer
597
564
  cls
598
565
  legend
599
566
 
600
- arena = arena_data
567
+ arena = Aromancer::Storage.get_arena
601
568
  Thread.main[:menu_options][__method__.to_sym] = [
602
569
  {name: I18n.t("shared.back"), value: :back}
603
570
  ] + arena["scroll_words"].map{|w| {name: w["value_display"], value: w["id"]}}
@@ -616,7 +583,7 @@ module Aromancer
616
583
  cls
617
584
  legend
618
585
 
619
- arena = arena_data
586
+ arena = Aromancer::Storage.get_arena
620
587
  Thread.main[:menu_options][__method__.to_sym] = [
621
588
  {name: I18n.t("shared.back"), value: :back}
622
589
  ] + arena["sentences"].map{|s| {name: s["value_display"], value: s["id"]}}
@@ -646,11 +613,12 @@ module Aromancer
646
613
  selected_word = possibilities["word"]
647
614
  for_type = possibilities["for_type"].to_sym
648
615
 
649
- arena = arena_data
616
+ arena = Aromancer::Storage.get_arena
650
617
  player_words = arena["player"]["words"]
651
618
 
652
619
  choices = [{name: I18n.t("shared.back"), value: :back}]
653
- if for_type == :player_word
620
+ if for_type == :player_word &&
621
+ arena["turn_player"]["id"] == Aromancer::Storage.get_player["id"]
654
622
 
655
623
  # show place on scroll option if selected word is from player's words
656
624
  choices << {
@@ -659,8 +627,11 @@ module Aromancer
659
627
  }
660
628
  end
661
629
 
662
- choices += options.map{|o| {name: "#{o["humanized_title"]} -> weight: #{o["total_weight"]}", value: o}}
630
+ unless arena["turn_player"]["id"] != Aromancer::Storage.get_player["id"]
631
+ choices += options.map{|o| {name: "#{o["humanized_title"]} -> weight: #{o["total_weight"]}", value: o}}
632
+ end
663
633
 
634
+ _muh_method = __method__.to_sym
664
635
  Thread.main[:menu_options][__method__.to_sym] = choices
665
636
  Thread.main[:menu_runners][__method__.to_sym] = [
666
637
  {value: :back, proc: Proc.new{
@@ -674,12 +645,24 @@ module Aromancer
674
645
  end
675
646
  }},
676
647
  {value: :player_word, proc: Proc.new{
648
+ Aromancer::Prompt.say(I18n.t("shared.spelling"))
649
+ Thread.main[:menu_options][_muh_method] = []
650
+ Thread.main[:menu_runners][_muh_method] = []
677
651
  Aromancer::Api.submit_turn(request_uuid)
678
- legend_menu
652
+ # websockets will trigger this for other player after turn is submitted
653
+ Aromancer::Api.get_legends
654
+ Aromancer::Api.load_arena
655
+ sleep(Aromancer::Cli::RENDER_DELAY)
679
656
  }},
680
657
  {value: nil, proc: Proc.new{|o|
658
+ Aromancer::Prompt.say(I18n.t("shared.spelling"))
659
+ Thread.main[:menu_options][_muh_method] = []
660
+ Thread.main[:menu_runners][_muh_method] = []
681
661
  Aromancer::Api.submit_turn(request_uuid, {option_uuid: o[:uuid.to_s]})
682
- legend_menu
662
+ # websockets will trigger this for other player after turn is submitted
663
+ Aromancer::Api.get_legends
664
+ Aromancer::Api.load_arena
665
+ sleep(Aromancer::Cli::RENDER_DELAY)
683
666
  }}
684
667
  ]
685
668
  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)
@@ -129,7 +128,7 @@ module Aromancer
129
128
 
130
129
  def self.get_arena
131
130
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
132
- return InternalError.build(StandardError.new("no active legend")) if legend_id.nil?
131
+ return InternalError.build(StandardError.new("#{__method__}: no active legend")) if legend_id.nil?
133
132
 
134
133
  begin
135
134
  Faraday.new(
@@ -143,13 +142,14 @@ module Aromancer
143
142
 
144
143
  def self.get_stream(count = nil)
145
144
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
146
- return InternalError.build(StandardError.new("no active legend")) if legend_id.nil?
145
+ return InternalError.build(StandardError.new("#{__method__}: no active legend")) if legend_id.nil?
147
146
 
147
+ count_param = count.nil? || count.to_i <= 0 ? "" : "?last_count=#{count}"
148
148
  begin
149
149
  Faraday.new(
150
150
  url: Aromancer::Storage.get_server_url,
151
151
  headers: HEADERS.merge(auth_header),
152
- ).get("/legends/#{legend_id}/stream?count=#{count || nil}")
152
+ ).get("/legends/#{legend_id}/stream#{count_param}")
153
153
  rescue StandardError => e
154
154
  InternalError.build(e)
155
155
  end
@@ -157,7 +157,7 @@ module Aromancer
157
157
 
158
158
  def self.get_word_possibilities(selected_word_id)
159
159
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
160
- return InternalError.build(StandardError.new("no active legend")) if legend_id.nil?
160
+ return InternalError.build(StandardError.new("#{__method__}: no active legend")) if legend_id.nil?
161
161
 
162
162
  begin
163
163
  Faraday.new(
@@ -171,7 +171,7 @@ module Aromancer
171
171
 
172
172
  def self.submit_turn(request_uuid, params = {})
173
173
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
174
- return InternalError.build(StandardError.new("no active legend")) if legend_id.nil?
174
+ return InternalError.build(StandardError.new("#{__method__}: no active legend")) if legend_id.nil?
175
175
 
176
176
  begin
177
177
  Faraday.new(