aromancer 0.0.8 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da80d9c4f943470ac226c37651e21eaa5ee12128beb9c00264b43ace9845c61c
4
- data.tar.gz: c55101847c0d3e6c14d7c821dc9fdf31d4e114d614d97957b7162ab995d5a02e
3
+ metadata.gz: ccf1d829b9e304436e6cba2d61dfa0dcc785faa3084fa1f7a1decb9db3e22f60
4
+ data.tar.gz: c633958a50ed14bbae44ec91f856dbb766fdafa3d0a938c785c5dc75b5efe097
5
5
  SHA512:
6
- metadata.gz: 706112cc7fbf39edadef53eb6ac54a73c4e43d17f0f3b288cb9c795ba937bc38ec8427bb74ddcfbd8c84411483c520a8d9ac9b576f4371c1f0c656c2e36adb69
7
- data.tar.gz: 91aa390ba4cf322eef5e616053cce00ebaba35ef0b9d13e051f2ba71a08bdf7c7ba5a9669d0279f88e7a67ed619a2cddba2b36f5eddc52854f691f2b74458fbc
6
+ metadata.gz: 1c77d8b6be396347a5cc7b9382beae520ca4dce5850cf32e1ad6848962a854fdb1392ce1a725cf5e93bc0430507f42ab9c7cd7a45e55523d72626b230b7966cd
7
+ data.tar.gz: c33e62ab2508e1fea739ab82f1480d0d66bd5f88b74492a093e9837fefb066ef94d34622d8f12778fe74a383aa07597a7680ca23fac869a4012fae33ce3fa941
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aromancer (0.0.5)
4
+ aromancer (0.1.0)
5
5
  activesupport (~> 8.1.4)
6
6
  faraday (~> 2.14.4)
7
7
  fileutils (~> 1.8.0)
@@ -171,7 +171,7 @@ DEPENDENCIES
171
171
 
172
172
  CHECKSUMS
173
173
  activesupport (8.1.4) sha256=891dd3fe43c4fc8391934b237b1189bb1f661c932a84a840043db9d46a4e80df
174
- aromancer (0.0.5)
174
+ aromancer (0.1.0)
175
175
  base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
176
176
  bigdecimal (4.1.3) sha256=61ebe1e5e559bdc3cc6f2c0ee7f427321fc838f59611c294356eb04d6e21cf66
177
177
  bundler (4.0.22) sha256=d8d5ec84c8555e0af71db63ed7aee4d1a8fb839ec46d84212d61979242a5d75a
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # [aromancer](https://rubygems.org/gems/aromancer)
1
+ # [aromancer(rubygems)](https://rubygems.org/gems/aromancer)
2
+ # [aromancer(github)](https://rubygems.org/gems/aromancer)
2
3
  ## word
3
4
  ### sentence
4
5
  #### scroll
data/aromancer.gemspec CHANGED
@@ -10,6 +10,8 @@
10
10
 
11
11
  =end
12
12
 
13
+ GEM_DESCRIPTION = "aromancer is a unix tarot card game."
14
+
13
15
  require_relative "lib/aromancer/version"
14
16
 
15
17
  Gem::Specification.new do |spec|
@@ -18,9 +20,9 @@ Gem::Specification.new do |spec|
18
20
  spec.authors = ["i2097i"]
19
21
  spec.email = ["i2097i@hotmail.com"]
20
22
 
21
- spec.description = ""
22
- spec.summary = ""
23
- spec.homepage = "https://github.com/i2097i/aromancer"
23
+ spec.description = GEM_DESCRIPTION + "\n#{Aromancer::VERSION} release notes: #{Aromancer::RELEASE_NOTES}"
24
+ spec.summary = GEM_DESCRIPTION
25
+ spec.homepage = "https://github.com/f-oss-om-foundation/aromancer"
24
26
  spec.license = "MIT"
25
27
  spec.files = `git ls-files`.split("\n").reject{|p| p.match?(/^(spec|.release|.*.gem$)/)}
26
28
  spec.bindir = "bin"
@@ -0,0 +1 @@
1
+ c113cc095e8e8621b438078a7708295b681cbe4887e0c2fa537c90c777c8f1bf548becf77efb1ae3ec0abfacc1c9fa43ff730ed82ffb4acd0dc62377ad9925cc
@@ -0,0 +1 @@
1
+ f835a07e99f0233d9050d3e256209fec23d71d682a2762379563b0f36769a7708fff1808d2d03ed6103ddcaa7d72f41ab410271f5b22c2f9d5d9fd4e6ae41f19
data/lib/aromancer/api.rb CHANGED
@@ -28,8 +28,10 @@ module Aromancer
28
28
  if response.status == 401
29
29
  Aromancer::Storage.set_signed_out_flag(true)
30
30
  player = Aromancer::Storage.get_player
31
- player["api_key"] = nil
32
- Aromancer::Storage.set_player(player)
31
+ unless player.nil?
32
+ player["api_key"] = nil
33
+ Aromancer::Storage.set_player(player)
34
+ end
33
35
  end
34
36
  end
35
37
 
@@ -130,7 +132,7 @@ module Aromancer
130
132
  player["active_legend_id"] = active_legend_id
131
133
  Aromancer::Storage.set_player(player)
132
134
  end
133
- Aromancer::Storage.instance.clear_cache!
135
+ Aromancer::Cli.instance.should_clear_cache = true
134
136
  result = Aromancer::Server.update_player({player: {
135
137
  active_legend_id: active_legend_id,
136
138
  status: active_legend_id.nil? ? :lobby : :playing
data/lib/aromancer/cli.rb CHANGED
@@ -15,44 +15,78 @@ module Aromancer
15
15
  class Cli
16
16
  include Singleton
17
17
 
18
- attr_accessor :ui_thread, :ws_thread, :ui_busy, :ws_busy, :last_render, :error_timeout
18
+ attr_accessor :error_timeout
19
+ attr_accessor :last_render
20
+ attr_accessor :should_clear_cache
21
+ attr_accessor :storage_mutex
22
+ attr_accessor :ui_busy, :ui_thread
23
+ attr_accessor :ws_busy, :ws_thread
24
+ attr_accessor :running_dimension
25
+
26
+ RENDER_DELAY = 0.1
27
+
28
+ def initialize
29
+ self.storage_mutex = Mutex.new
30
+ self.should_clear_cache = false
31
+ self.last_render = 0
32
+ self.error_timeout = Time.now.to_i
19
33
 
20
- THROTTLE_MS = 0.1
34
+ Thread.main[:route] = :authentication
35
+ Thread.main[:menu_runners] = {}
36
+ Thread.main[:menu_options] = {}
37
+ end
38
+
39
+ def self.safe_exit!
40
+ if self.instance.running_dimension == :plugin_mode
41
+ raise "plugin_mode"
42
+ else
43
+ exit
44
+ end
45
+ end
21
46
 
22
47
  # user entry point
23
- def self.run
48
+ def self.run(dimension = :default)
49
+ self.instance.running_dimension = dimension
24
50
  Aromancer::Websocket.instance
25
- Aromancer::Storage.instance
26
-
27
- self.instance.last_render = 0
28
- self.instance.error_timeout = Time.now.to_i
51
+ Aromancer::Storage.instance.ensure_default_preferences_exist
29
52
 
30
53
  # load player on-start
31
- Aromancer::Api.set_active_legend_id(nil) unless Aromancer::Storage.get_player.nil?
54
+ Aromancer::Api.set_active_legend_id(
55
+ ({} || Aromancer::Storage.get_player)[:active_legend_id.to_s]
56
+ ) unless Aromancer::Storage.get_player.nil?
32
57
 
33
- Thread.main[:route] = :authentication
34
- Thread.main[:menu_runners] = {}
35
- Thread.main[:menu_options] = {}
36
58
  Aromancer::Prompt.say(I18n.t("shared.welcome", version: Aromancer::VERSION))
37
- Aromancer::Prompt.say(I18n.t("shared.server_url", url: Aromancer::Storage::get_server_url))
59
+
38
60
  self.instance.start_ui_thread
39
61
  self.instance.start_ws_thread
40
62
  loop do
41
63
  begin
64
+
65
+ if self.instance.should_clear_cache
66
+ Aromancer::Storage.instance.clear_cache!
67
+ self.instance.should_clear_cache = false
68
+ end
69
+
42
70
  self.instance.ui_thread.join
71
+
43
72
  rescue NoMethodError => e
73
+ Aromancer::Storage.set_last_error({
74
+ status: -1,
75
+ headers: e.to_s,
76
+ body: e.inspect.to_s
77
+ })
44
78
  if Aromancer::Storage.get_preference(:debug)
45
79
  Aromancer::Prompt.say(I18n.t("shared.last_error"))
46
- Aromancer::Prompt.say(JSON.pretty_generate(e[:body.to_s]))
47
- Aromancer::Prompt.say("sleeping 5 on main thread...")
48
- sleep(5)
80
+ Aromancer::Prompt.say("sleeping 1 on main thread...")
81
+ sleep(1)
49
82
  end
83
+ Aromancer::Storage.instance.clear_cache!
50
84
  self.instance.start_ui_thread
51
85
  self.instance.start_ws_thread
52
86
  sleep(1)
53
87
  rescue Interrupt => e
54
88
  Aromancer::Prompt.say("interrupt on main thread...exiting immediately.")
55
- exit
89
+ return Aromancer::Cli.safe_exit!
56
90
  end
57
91
  end
58
92
  end
@@ -76,11 +110,10 @@ module Aromancer
76
110
  menu_runners.empty?
77
111
 
78
112
  Aromancer::Routes.resume
79
- sleep(THROTTLE_MS)
113
+ sleep(Aromancer::Cli::RENDER_DELAY)
80
114
  Aromancer.print_hud
81
115
 
82
116
  v = Aromancer::Prompt.p.select("", menu_options, show_help: :always, cycle: true, per_page: 11)
83
- Aromancer.print_hud
84
117
  runners = menu_runners.select{|r| r[:value] == v}
85
118
  runners = menu_runners.select{|r| r[:value].nil?} if runners.empty?
86
119
 
@@ -90,12 +123,13 @@ module Aromancer
90
123
  end
91
124
 
92
125
  else
93
- sleep(THROTTLE_MS)
126
+ sleep(Aromancer::Cli::RENDER_DELAY)
94
127
  Aromancer::Routes.resume
128
+ Aromancer.print_hud
95
129
  end
96
130
  Aromancer::Cli.instance.ui_busy = false
97
131
  Aromancer::Cli.instance.last_render = Time.now
98
- sleep(THROTTLE_MS)
132
+ sleep(Aromancer::Cli::RENDER_DELAY)
99
133
  end
100
134
  end
101
135
  end
@@ -121,12 +155,12 @@ module Aromancer
121
155
  Aromancer::Websocket.instance.connect
122
156
  if Aromancer::Storage.get_arena.nil?
123
157
  Aromancer::Api.load_arena
124
- sleep(1)
158
+ sleep(Aromancer::Cli::RENDER_DELAY)
125
159
  Aromancer::Cli.instance.start_ui_thread(true)
126
160
  end
127
161
  end
128
162
  @ws_busy = false
129
- sleep(1)
163
+ sleep(Aromancer::Cli::RENDER_DELAY)
130
164
  end
131
165
  end
132
166
  end
@@ -75,7 +75,7 @@ module Aromancer
75
75
  configure
76
76
  }},
77
77
  {value: :exit, proc: Proc.new{
78
- exit
78
+ Aromancer::Cli.safe_exit!
79
79
  }}
80
80
  ]
81
81
  Thread.main[:route] = __method__.to_sym
@@ -122,7 +122,7 @@ module Aromancer
122
122
  Aromancer::Storage.instance.set_key(storage_key, previous)
123
123
  end
124
124
 
125
- Aromancer::Storage.instance.clear_cache!
125
+ Aromancer::Cli.instance.should_clear_cache = true
126
126
  end
127
127
  Aromancer::Prompt.say(I18n.t("shared.server_url", url: Aromancer::Storage.get_server_url))
128
128
  }
@@ -151,7 +151,7 @@ module Aromancer
151
151
  Aromancer::Prompt.say(
152
152
  I18n.t("routes.configure.force_ssl_toggle", value: Aromancer::Storage.get_preference(:force_ssl))
153
153
  )
154
- sleep(2)
154
+ sleep(1)
155
155
  configure
156
156
  }},
157
157
  {value: :debug, proc: Proc.new{
@@ -160,7 +160,7 @@ module Aromancer
160
160
  Aromancer::Prompt.say(
161
161
  I18n.t("routes.configure.debug_toggle", value: Aromancer::Storage.get_preference(:debug))
162
162
  )
163
- sleep(2)
163
+ sleep(1)
164
164
  configure
165
165
  }},
166
166
  ]
@@ -223,8 +223,8 @@ module Aromancer
223
223
  Thread.main[:route_params] = [params]
224
224
  new_game(params)
225
225
  }},
226
- {value: :load, proc: Proc.new{ Aromancer::Routes::legends }},
227
- {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 }},
228
228
  {value: :configure, proc: Proc.new{
229
229
  configure
230
230
  }},
@@ -241,7 +241,7 @@ module Aromancer
241
241
  end
242
242
  }},
243
243
  {value: :exit, proc: Proc.new{
244
- exit
244
+ Aromancer::Cli.safe_exit!
245
245
  }}
246
246
  ]
247
247
  Thread.main[:route] = __method__.to_sym
@@ -268,11 +268,11 @@ module Aromancer
268
268
  Thread.main[:menu_runners][__method__.to_sym] = [
269
269
  {value: :continue, proc: Proc.new{
270
270
  Aromancer::Api.create_legend(params)
271
- legend_menu
271
+ Thread.main[:route] = :legend_menu
272
272
  }},
273
273
  {value: :cancel, proc: Proc.new{
274
274
  Aromancer::Prompt.say(I18n.t("routes.new_game.cancelled"))
275
- main_menu
275
+ Thread.main[:route] = :main_menu
276
276
  }}
277
277
  ]
278
278
  Thread.main[:route] = __method__.to_sym
@@ -287,11 +287,12 @@ module Aromancer
287
287
  # if legend_array.nil?, load player's legends
288
288
  if legend_array.nil?
289
289
  Aromancer::Api.get_legends
290
- legend_array = Aromancer::Storage.get_legends
290
+ sleep(Aromancer::Cli::RENDER_DELAY)
291
+ legend_array = Aromancer::Storage.get_legends || []
291
292
  unless legend_array.any?
292
293
  Aromancer::Prompt.say(I18n.t("shared.empty"))
293
294
  sleep(1)
294
- return main_menu
295
+ Thread.main[:route] = :main_menu
295
296
  end
296
297
  end
297
298
 
@@ -309,17 +310,17 @@ module Aromancer
309
310
  Thread.main[:menu_runners][__method__.to_sym] = [
310
311
  {value: :back, proc: Proc.new{
311
312
  Aromancer::Api.set_active_legend_id(nil)
312
- main_menu
313
+ Thread.main[:route] = :main_menu
313
314
  }},
314
315
  ] + legend_array.map{|l|
315
316
  {
316
317
  value: l["id"],
317
318
  proc: Proc.new{
318
319
  Aromancer::Api.set_active_legend_id(l["id"])
319
- sleep(1)
320
+ sleep(Aromancer::Cli::RENDER_DELAY)
320
321
  Aromancer::Api.get_legends
321
322
 
322
- legend_menu
323
+ Thread.main[:route] = :legend_menu
323
324
  }
324
325
  }
325
326
  }
@@ -330,9 +331,9 @@ module Aromancer
330
331
  return if Thread.main[:route] == __method__.to_sym
331
332
  Aromancer::Prompt.print_divider(I18n.t("routes.stream.title"))
332
333
  Aromancer::Api.load_stream(recent_count)
333
- stream = Aromancer::Storage.get_stream
334
- stream["stream"].last(
335
- 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
336
337
  ).each{|e|
337
338
  Aromancer::Prompt.say("[#{Aromancer.time_display(e["updated_at"])}]: #{e["description"]}", ljust: true)
338
339
  }
@@ -363,19 +364,21 @@ module Aromancer
363
364
  Thread.main[:route] = __method__.to_sym
364
365
  case al_status
365
366
  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
- ]
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
379
382
  when :complete
380
383
  Thread.main[:menu_options][__method__.to_sym] = [
381
384
  {name: I18n.t("shared.key_press"), value: :key_press}
@@ -384,7 +387,7 @@ module Aromancer
384
387
  {value: :key_press, proc: Proc.new{
385
388
  Aromancer::Prompt.say(I18n.t("routes.legend.returning_to_", route: :legends))
386
389
  Aromancer::Api.set_active_legend_id(nil)
387
- legends
390
+ Thread.main[:route] = :legends
388
391
  }}
389
392
  ]
390
393
  end
@@ -393,10 +396,10 @@ module Aromancer
393
396
 
394
397
  arena = Aromancer::Storage.get_arena
395
398
  if arena.nil? || arena["turn_player"].nil?
396
- Aromancer::Prompt.say(I18n.t("shared.waiting"))
399
+ Aromancer::Prompt.say(I18n.t("shared.spelling"))
397
400
  Thread.main[:menu_options][__method__.to_sym] = []
398
401
  Thread.main[:menu_runners][__method__.to_sym] = []
399
- sleep(1)
402
+ sleep(Aromancer::Cli::RENDER_DELAY)
400
403
  Aromancer::Api.get_legends
401
404
  Aromancer::Api.load_arena
402
405
  return
@@ -535,10 +538,13 @@ module Aromancer
535
538
  legend
536
539
 
537
540
  arena = Aromancer::Storage.get_arena
538
- if arena["player"].nil? || arena["player"]["words"].nil?
541
+ if arena.nil? ||
542
+ arena["player"].nil? ||
543
+ arena["player"]["words"].nil?
544
+ sleep(Aromancer::Cli::RENDER_DELAY)
545
+
539
546
  Aromancer::Api.load_arena
540
- sleep(1)
541
- main_menu
547
+ return
542
548
  end
543
549
  Thread.main[:menu_options][__method__.to_sym] = [
544
550
  {name: I18n.t("shared.back"), value: :back}
@@ -639,24 +645,24 @@ module Aromancer
639
645
  end
640
646
  }},
641
647
  {value: :player_word, proc: Proc.new{
642
- Aromancer::Prompt.say(I18n.t("shared.waiting"))
648
+ Aromancer::Prompt.say(I18n.t("shared.spelling"))
643
649
  Thread.main[:menu_options][_muh_method] = []
644
650
  Thread.main[:menu_runners][_muh_method] = []
645
651
  Aromancer::Api.submit_turn(request_uuid)
646
652
  # websockets will trigger this for other player after turn is submitted
647
653
  Aromancer::Api.get_legends
648
654
  Aromancer::Api.load_arena
649
- sleep(1)
655
+ sleep(Aromancer::Cli::RENDER_DELAY)
650
656
  }},
651
657
  {value: nil, proc: Proc.new{|o|
652
- Aromancer::Prompt.say(I18n.t("shared.waiting"))
658
+ Aromancer::Prompt.say(I18n.t("shared.spelling"))
653
659
  Thread.main[:menu_options][_muh_method] = []
654
660
  Thread.main[:menu_runners][_muh_method] = []
655
661
  Aromancer::Api.submit_turn(request_uuid, {option_uuid: o[:uuid.to_s]})
656
662
  # websockets will trigger this for other player after turn is submitted
657
663
  Aromancer::Api.get_legends
658
664
  Aromancer::Api.load_arena
659
- sleep(1)
665
+ sleep(Aromancer::Cli::RENDER_DELAY)
660
666
  }}
661
667
  ]
662
668
  Thread.main[:route_params] = [selected_word_id]
@@ -128,7 +128,7 @@ module Aromancer
128
128
 
129
129
  def self.get_arena
130
130
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
131
- 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?
132
132
 
133
133
  begin
134
134
  Faraday.new(
@@ -142,13 +142,14 @@ module Aromancer
142
142
 
143
143
  def self.get_stream(count = nil)
144
144
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
145
- 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?
146
146
 
147
+ count_param = count.nil? || count.to_i <= 0 ? "" : "?last_count=#{count}"
147
148
  begin
148
149
  Faraday.new(
149
150
  url: Aromancer::Storage.get_server_url,
150
151
  headers: HEADERS.merge(auth_header),
151
- ).get("/legends/#{legend_id}/stream?count=#{count || nil}")
152
+ ).get("/legends/#{legend_id}/stream#{count_param}")
152
153
  rescue StandardError => e
153
154
  InternalError.build(e)
154
155
  end
@@ -156,7 +157,7 @@ module Aromancer
156
157
 
157
158
  def self.get_word_possibilities(selected_word_id)
158
159
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
159
- 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?
160
161
 
161
162
  begin
162
163
  Faraday.new(
@@ -170,7 +171,7 @@ module Aromancer
170
171
 
171
172
  def self.submit_turn(request_uuid, params = {})
172
173
  legend_id = (Aromancer::Storage.get_player || {})["active_legend_id"]
173
- 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?
174
175
 
175
176
  begin
176
177
  Faraday.new(
@@ -52,8 +52,6 @@ module Aromancer
52
52
  :port
53
53
  ]
54
54
 
55
- DEFAULT_SERVER = "http://127.0.0.1"
56
-
57
55
  DEFAULT_PREFERENCES = {
58
56
  preference_debug: false,
59
57
  preference_force_ssl: false,
@@ -61,18 +59,19 @@ module Aromancer
61
59
  preference_hide_stream: true,
62
60
  }
63
61
 
62
+ DEFAULT_SERVER_URL = :"http://127.0.0.1:3000".to_s
63
+
64
64
  attr_accessor :storage_open, :cache, :clear_flag, :parser_error
65
65
 
66
66
  def initialize
67
67
  reload!
68
- ensure_default_preferences_exist
69
68
  end
70
69
 
71
70
  def ensure_default_preferences_exist
72
- DEFAULT_PREFERENCES.keys.each{|d_key|
71
+ DEFAULT_PREFERENCES.each{|d_key, d_value|
73
72
  current_value = get_key(d_key)
74
73
  if current_value.nil? || ![TrueClass, FalseClass].include?(current_value.class)
75
- set_key(d_key.to_s, DEFAULT_PREFERENCES[d_key])
74
+ set_key(d_key.to_s, d_value)
76
75
  end
77
76
  }
78
77
  end
@@ -82,7 +81,7 @@ module Aromancer
82
81
  @clear_flag = false
83
82
  @parser_error = nil
84
83
  clear_cache!
85
- FileUtils.mkdir_p(Aromancer.home_directory)
84
+ Aromancer.configure_home
86
85
  end
87
86
 
88
87
  def clear_cache!
@@ -127,13 +126,15 @@ module Aromancer
127
126
  end
128
127
 
129
128
  def self.storage_filepath
130
- filepath = File.join(Aromancer.home_directory, "storage.json")
129
+ filepath = File.join(Aromancer.home_directory, "v#{Aromancer::VERSION}.json")
131
130
 
132
131
  # create storage file if not present
133
132
  unless File.exist?(filepath)
134
133
  File.open(filepath, "w+") do |f|
135
- f.write({version: Aromancer::VERSION, created: Time.now}.to_json)
134
+ f.write({created_at: Time.now}.to_json)
136
135
  end
136
+ else
137
+
137
138
  end
138
139
 
139
140
  filepath
@@ -230,12 +231,12 @@ module Aromancer
230
231
  instance.set_key("server_url_#{k}", uri.select(k).first)
231
232
  }
232
233
  elsif get_server_url.nil?
233
- set_server_url(DEFAULT_SERVER)
234
+ set_server_url(DEFAULT_SERVER_URL)
234
235
  end
235
236
  end
236
237
 
237
238
  def self.get_server_url
238
- set_server_url(DEFAULT_SERVER) if URI_KEYS.all?{|k| Aromancer::Storage.instance.get_key("server_url_#{k}").nil?}
239
+ set_server_url(DEFAULT_SERVER_URL) if URI_KEYS.all?{|k| Aromancer::Storage.instance.get_key("server_url_#{k}").nil?}
239
240
  URI.parse(URI_KEYS.map{|k|
240
241
  c = Aromancer::Storage.instance.get_key("server_url_#{k}")
241
242
  case k
@@ -268,102 +269,111 @@ module Aromancer
268
269
  URI.parse("#{w_scheme}://#{host}:#{port}/#{w_path}").to_s
269
270
  end
270
271
 
272
+ def dump_game_state
273
+ Aromancer::Cli.instance.storage_mutex.synchronize do
274
+ return JSON.parse(File.read(Aromancer::Storage.storage_filepath, encoding: "UTF-8"))
275
+ end
276
+ end
277
+
271
278
  def get_key(key)
272
- key = key.to_s
279
+ Aromancer::Cli.instance.storage_mutex.synchronize do
280
+ key = key.to_s
273
281
 
274
- # ensure default for key exists
275
- @cache[key] = {value: nil, persisted: false} unless @cache.keys.include?(key)
276
- if false && (@cache[:preference_debug.to_s] || {value: DEFAULT_PREFERENCES[:preference_debug]})[:value]
277
- Aromancer::Prompt.say("#{__method__} > @cache[#{key}]=#{@cache[key]}")
278
- end
279
- # return cache value if storage open or the cache value is persisted
280
- return @cache[key][:value] if @storage_open || @cache[key][:persisted]
281
-
282
- # open storage
283
- @storage_open = true
284
- storage_contents = {}
285
- begin
286
- @parser_error = nil
287
- # read storage
288
- storage_contents = JSON.parse(File.read(Aromancer::Storage.storage_filepath, encoding: "UTF-8"))
289
- rescue StandardError => e
290
- @storage_open = false
291
- if @parser_error.nil?
292
- @parser_error = e
293
- return get_key(key)
282
+ # ensure default for key exists
283
+ @cache[key] = {value: nil, persisted: false} unless @cache.keys.include?(key)
284
+ if false && (@cache[:preference_debug.to_s] || {value: DEFAULT_PREFERENCES[:preference_debug]})[:value]
285
+ Aromancer::Prompt.say("#{__method__} > @cache[#{key}]=#{@cache[key]}")
286
+ end
287
+ # return cache value if storage open or the cache value is persisted
288
+ return @cache[key][:value] if @storage_open || @cache[key][:persisted]
289
+
290
+ # open storage
291
+ @storage_open = true
292
+ storage_contents = {}
293
+ begin
294
+ @parser_error = nil
295
+ # read storage
296
+ storage_contents = JSON.parse(File.read(Aromancer::Storage.storage_filepath, encoding: "UTF-8"))
297
+ rescue StandardError => e
298
+ @storage_open = false
299
+ if @parser_error.nil?
300
+ @parser_error = e
301
+ return get_key(key)
302
+ else
303
+ raise @parser_error
304
+ end
305
+ end
306
+
307
+ # only update the cache value if present in storage
308
+ if storage_contents.keys.include?(key)
309
+ @cache[key] = {value: storage_contents[key], persisted: true}
294
310
  else
295
- raise @parser_error
311
+ @cache[key][:persisted] = false
296
312
  end
297
- end
298
313
 
299
- # only update the cache value if present in storage
300
- if storage_contents.keys.include?(key)
301
- @cache[key] = {value: storage_contents[key], persisted: true}
302
- else
303
- @cache[key][:persisted] = false
314
+ value = @cache[key][:value]
315
+ @storage_open = false
316
+ clear_cache! if @clear_flag
317
+ return value
304
318
  end
305
-
306
- value = @cache[key][:value]
307
- @storage_open = false
308
- clear_cache! if @clear_flag
309
- return value
310
319
  end
311
320
 
312
321
  def set_key(key, value)
313
- key = key.to_s
322
+ Aromancer::Cli.instance.storage_mutex.synchronize do
323
+ key = key.to_s
314
324
 
315
- # ensure default for key exists
316
- @cache[key] = {value: value, persisted: false} unless @cache.keys.include?(key)
325
+ # ensure default for key exists
326
+ @cache[key] = {value: value, persisted: false} unless @cache.keys.include?(key)
317
327
 
318
- # assign new cache value and set persisted to false
319
- @cache[key][:value] = value
320
- @cache[key][:persisted] = false
328
+ # assign new cache value and set persisted to false
329
+ @cache[key][:value] = value
330
+ @cache[key][:persisted] = false
321
331
 
322
- if @storage_open && (@cache[:preference_debug.to_s] || {value: DEFAULT_PREFERENCES[:preference_debug]})[:value]
323
- puts Thread.current.backtrace
324
- Aromancer::Prompt.say("#{__method__} > @cache[#{key}]=#{@cache[key]}")
325
- end
326
- # return if storage open
327
- # non-persisted cache values update next cycle
328
- return if @storage_open
329
-
330
- # open storage
331
- @storage_open = true
332
- storage_contents = {}
333
- begin
334
- @parser_error = nil
335
- # read storage
336
- storage_contents = JSON.parse(File.read(Aromancer::Storage.storage_filepath, encoding: "UTF-8"))
337
- rescue StandardError => e
338
- @storage_open = false
339
- if @parser_error.nil?
340
- @parser_error = e
341
- return get_key(key)
342
- else
343
- raise @parser_error
332
+ if @storage_open && (@cache[:preference_debug.to_s] || {value: DEFAULT_PREFERENCES[:preference_debug]})[:value]
333
+ Aromancer::Prompt.say("#{__method__} > @cache[#{key}]=#{@cache[key]}")
334
+ end
335
+ # return if storage open
336
+ # non-persisted cache values update next cycle
337
+ return if @storage_open
338
+
339
+ # open storage
340
+ @storage_open = true
341
+ storage_contents = {}
342
+ begin
343
+ @parser_error = nil
344
+ # read storage
345
+ storage_contents = JSON.parse(File.read(Aromancer::Storage.storage_filepath, encoding: "UTF-8"))
346
+ rescue StandardError => e
347
+ @storage_open = false
348
+ if @parser_error.nil?
349
+ @parser_error = e
350
+ return get_key(key)
351
+ else
352
+ raise @parser_error
353
+ end
344
354
  end
345
- end
346
355
 
347
- # update storage and cache
348
- ([key] + @cache.keys.select{|k|
349
- !@cache[k][:persisted]
350
- }).each{|k|
351
- storage_contents[k] = @cache[k][:value]
352
- @cache[k][:persisted] = true
353
- }
356
+ # update storage and cache
357
+ ([key] + @cache.keys.select{|k|
358
+ !@cache[k][:persisted]
359
+ }).each{|k|
360
+ storage_contents[k] = @cache[k][:value]
361
+ @cache[k][:persisted] = true
362
+ }
354
363
 
355
- # write storage
356
- File.open(Aromancer::Storage.storage_filepath, "w+") do |f|
357
- f.write(storage_contents.to_json)
358
- end
364
+ # write storage
365
+ File.open(Aromancer::Storage.storage_filepath, "w+") do |f|
366
+ f.write(storage_contents.to_json)
367
+ end
359
368
 
360
- if (@cache[:preference_debug.to_s] || {value: DEFAULT_PREFERENCES[:preference_debug]})[:value]
361
- Aromancer::Prompt.say("#{__method__} > @cache[#{key}]=#{@cache[key]}")
362
- end
369
+ if (@cache[:preference_debug.to_s] || {value: DEFAULT_PREFERENCES[:preference_debug]})[:value]
370
+ Aromancer::Prompt.say("#{__method__} > @cache[#{key}]=#{@cache[key]}")
371
+ end
363
372
 
364
- # close storage
365
- @storage_open = false
366
- clear_cache! if @clear_flag
373
+ # close storage
374
+ @storage_open = false
375
+ clear_cache! if @clear_flag
376
+ end
367
377
  end
368
378
  end
369
379
  end
@@ -11,5 +11,8 @@
11
11
  =end
12
12
 
13
13
  module Aromancer
14
- VERSION = "0.0.8"
14
+ VERSION = "0.1.0"
15
+ RELEASE_NOTES = [
16
+ :adds_oss_om_plugin
17
+ ].join(" | ")
15
18
  end
@@ -54,7 +54,7 @@ module Aromancer
54
54
  legend_id = payload["message"]["id"]
55
55
  lid = Aromancer::Storage.get_player&.symbolize_keys[:active_legend_id]
56
56
  if !lid.nil? && lid == legend_id.to_i
57
- Aromancer::Storage.instance.clear_cache!
57
+ Aromancer::Cli.instance.should_clear_cache = true
58
58
  Aromancer::Api.get_legends
59
59
  Aromancer::Api.load_arena
60
60
  sleep(1)
data/lib/aromancer.rb CHANGED
@@ -28,6 +28,10 @@ module Aromancer
28
28
  Aromancer::Prompt.say(Aromancer::FONT.write(text, letter_spacing: letter_spacing))
29
29
  end
30
30
 
31
+ def self.configure_home
32
+ FileUtils.mkdir_p(Aromancer.home_directory) unless Dir.exist? Aromancer.home_directory
33
+ end
34
+
31
35
  def self.home_directory
32
36
  "#{`echo $HOME`.strip}/.aromancer"
33
37
  end
@@ -51,9 +55,33 @@ module Aromancer
51
55
  else
52
56
  I18n.t("shared.signed_in_as", as: Aromancer::Storage.get_player["alias"])
53
57
  end
58
+ server_status = I18n.t("shared.server_url", url: Aromancer::Storage::get_server_url)
59
+ force_ssl_value = Aromancer::Storage.get_preference(:force_ssl)
60
+ force_ssl_status_symbol = (
61
+ force_ssl_value
62
+ ) ? UNICODE[:check] : UNICODE[:close]
63
+ force_ssl_status = "ssl: #{force_ssl_status_symbol}"
64
+
65
+ debug_value = Aromancer::Storage.get_preference(:debug)
66
+ hud = [
67
+ nil,
68
+ player_status,
69
+ server_status,
70
+ force_ssl_status,
71
+ websocket_status,
72
+ :v.to_s + Aromancer::VERSION,
73
+ nil
74
+ ]
75
+
76
+ if debug_value
77
+ debug_status_symbol = (
78
+ debug_value
79
+ ) ? UNICODE[:check] : UNICODE[:close]
80
+ hud.insert(1, "d: #{debug_status_symbol}")
81
+ end
54
82
 
55
83
  Aromancer::Prompt.say(
56
- [nil, :v.to_s + Aromancer::VERSION, player_status, websocket_status, nil,].join(" | ")
84
+ hud.join(" | ")
57
85
  )
58
86
  end
59
87
 
@@ -85,4 +113,5 @@ module Aromancer
85
113
 
86
114
  Aromancer::Prompt.say(I18n.t(i18n_key || "shared.last_error", status: last_error[:status], error: message), rjust: true)
87
115
  end
116
+
88
117
  end
data/locale/en.yml CHANGED
@@ -6,14 +6,14 @@ en:
6
6
  key_press: "press enter to continue: "
7
7
  inturrupt: "exiting due to user inturrupt..."
8
8
  reader_initialized: "input reader initialized."
9
- welcome: "welcome to aromancer. loading v%{version}..."
9
+ welcome: "welcome aromancer. loading v%{version}..."
10
10
  server_url: "current server: %{url}"
11
11
  navigate: "navigate to %{route}."
12
12
  update_cancel: "update cancelled."
13
13
  update_confirm: "confirm update [%{new_value}] (enter y): "
14
14
  signed_in_as: "authenticated as %{as}"
15
15
  last_error: "error (%{status}). %{error}"
16
- waiting: "waiting..."
16
+ spelling: "spelling..."
17
17
  back: "back"
18
18
  exit: "exit"
19
19
  routes:
data/oss_om_plugin.rb ADDED
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+
5
+ aromancer_plugin.rb
6
+
7
+ aro dom aromancer plugin
8
+
9
+ by i2097i
10
+
11
+ =end
12
+
13
+ module Aro
14
+ module Dom
15
+ class AromancerPlugin
16
+
17
+ EXCLUDE_KEYS = [
18
+ "last_error"
19
+ ]
20
+ def self.oss_om_start!(plugin_data = {})
21
+ Aro::P.less(:aromancer_plugin_starting)
22
+
23
+ aromancer_installed = system("#{:which} -#{:s} #{:aromancer}")
24
+ Aro::P.say("aromancer_installed: #{aromancer_installed}")
25
+ raise "aromancer not installed!" unless aromancer_installed
26
+
27
+ aromancer_thread = Thread.new{
28
+ require :aromancer.to_s
29
+ begin
30
+ return Aromancer::Cli.run(:plugin_mode)
31
+ rescue StandardError => e
32
+ Aromancer::Prompt.say("aromancer thread threw an error: #{e}")
33
+ raise e
34
+ end
35
+ }
36
+
37
+ begin
38
+ Aro::P.say("aromancer_thread.join")
39
+ aromancer_thread.join
40
+ rescue StandardError => e
41
+ Aro::P.less(e.inspect)
42
+ Aro::P.say("#{e}")
43
+ end
44
+
45
+ require :aromancer.to_s
46
+ game_state = Aromancer::Storage.instance.dump_game_state.stringify_keys
47
+ game_state["plugin_file_path"] = plugin_data["plugin_file_path"]
48
+ game_state["oss_om_type"] = plugin_data["oss_om_type"]
49
+ return game_state.except(*Aro::Dom::AromancerPlugin::EXCLUDE_KEYS)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
data/tasks/make.rake CHANGED
@@ -1,4 +1,4 @@
1
- desc "rake install"
1
+ desc "rake install && rake build:checksum && bundle info aro"
2
2
  task :make do
3
- exec "rake install"
3
+ exec "rake install && rake build:checksum && bundle info aro"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aromancer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - i2097i
@@ -219,7 +219,9 @@ dependencies:
219
219
  - - "~>"
220
220
  - !ruby/object:Gem::Version
221
221
  version: 0.8.2
222
- description: ''
222
+ description: |-
223
+ aromancer is a unix tarot card game.
224
+ 0.1.0 release notes: adds_oss_om_plugin
223
225
  email:
224
226
  - i2097i@hotmail.com
225
227
  executables:
@@ -248,6 +250,8 @@ files:
248
250
  - checksums/aromancer-0.0.6.gem.sha512
249
251
  - checksums/aromancer-0.0.7.gem.sha512
250
252
  - checksums/aromancer-0.0.8.gem.sha512
253
+ - checksums/aromancer-0.0.9.gem.sha512
254
+ - checksums/aromancer-0.1.0.gem.sha512
251
255
  - lib/aromancer.rb
252
256
  - lib/aromancer/.DS_Store
253
257
  - lib/aromancer/api.rb
@@ -262,11 +266,11 @@ files:
262
266
  - lib/reiquire.rb
263
267
  - listen.rb
264
268
  - locale/en.yml
265
- - pre-commit.git.template
269
+ - oss_om_plugin.rb
266
270
  - sig/aromancer.rbs
267
271
  - tasks/console.rake
268
272
  - tasks/make.rake
269
- homepage: https://github.com/i2097i/aromancer
273
+ homepage: https://github.com/f-oss-om-foundation/aromancer
270
274
  licenses:
271
275
  - MIT
272
276
  metadata: {}
@@ -287,5 +291,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
291
  requirements: []
288
292
  rubygems_version: 4.0.21
289
293
  specification_version: 4
290
- summary: ''
294
+ summary: aromancer is a unix tarot card game.
291
295
  test_files: []
@@ -1,5 +0,0 @@
1
- #!/bin/sh
2
-
3
- echo "pre-commit hook"
4
- echo "rake build:checksum && git add checksums/"
5
- rake build:checksum && git add checksums/