aromancer 0.0.8 → 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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/checksums/aromancer-0.0.9.gem.sha512 +1 -0
- data/lib/aromancer/api.rb +5 -3
- data/lib/aromancer/cli.rb +39 -20
- data/lib/aromancer/routes.rb +44 -38
- data/lib/aromancer/server.rb +6 -5
- data/lib/aromancer/storage.rb +94 -89
- data/lib/aromancer/unix_dom.rb +13 -0
- data/lib/aromancer/version.rb +1 -1
- data/lib/aromancer/websocket.rb +1 -1
- data/lib/aromancer.rb +41 -1
- data/locale/en.yml +2 -2
- metadata +3 -2
- data/pre-commit.git.template +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 635ad1d6e0100e8311e7d9a2ed2d810e939684c02dc3572fbb6150cda376a90a
|
|
4
|
+
data.tar.gz: f3c3c71736c9c1ea4bf339ad6b3b804b302526f8b063de19d64138cdfa539792
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1284816493145370d4f997a9e5e0ffd74791faa5c7ddd8ca9d131ed0e1ebd7189026d238cc7f3999714cf2235f198be2a1c64e9f2aae9f812a9463ff1672cb7e
|
|
7
|
+
data.tar.gz: 19d0046c8683d31847cd51b59b0228eff1cca91a15eb4af6160cbc526294c032ed3fcc21ad8c60d7de9154137af35260106b9c83a6e1af6f7adf0b254d89e1d2
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
aromancer (0.0.
|
|
4
|
+
aromancer (0.0.9)
|
|
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.
|
|
174
|
+
aromancer (0.0.9)
|
|
175
175
|
base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
|
|
176
176
|
bigdecimal (4.1.3) sha256=61ebe1e5e559bdc3cc6f2c0ee7f427321fc838f59611c294356eb04d6e21cf66
|
|
177
177
|
bundler (4.0.22) sha256=d8d5ec84c8555e0af71db63ed7aee4d1a8fb839ec46d84212d61979242a5d75a
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c113cc095e8e8621b438078a7708295b681cbe4887e0c2fa537c90c777c8f1bf548becf77efb1ae3ec0abfacc1c9fa43ff730ed82ffb4acd0dc62377ad9925cc
|
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
|
|
32
|
-
|
|
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::
|
|
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,38 +15,57 @@ module Aromancer
|
|
|
15
15
|
class Cli
|
|
16
16
|
include Singleton
|
|
17
17
|
|
|
18
|
-
attr_accessor :
|
|
18
|
+
attr_accessor :error_timeout, :last_render, :should_clear_cache, :storage_mutex, :ui_busy, :ui_thread, :ws_busy, :ws_thread
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
RENDER_DELAY = 0.1
|
|
21
|
+
|
|
22
|
+
def initialize
|
|
23
|
+
self.storage_mutex = Mutex.new
|
|
24
|
+
self.should_clear_cache = false
|
|
25
|
+
self.last_render = 0
|
|
26
|
+
self.error_timeout = Time.now.to_i
|
|
27
|
+
|
|
28
|
+
Thread.main[:route] = :authentication
|
|
29
|
+
Thread.main[:menu_runners] = {}
|
|
30
|
+
Thread.main[:menu_options] = {}
|
|
31
|
+
end
|
|
21
32
|
|
|
22
33
|
# user entry point
|
|
23
34
|
def self.run
|
|
24
35
|
Aromancer::Websocket.instance
|
|
25
|
-
Aromancer::Storage.instance
|
|
26
|
-
|
|
27
|
-
self.instance.last_render = 0
|
|
28
|
-
self.instance.error_timeout = Time.now.to_i
|
|
36
|
+
Aromancer::Storage.instance.ensure_default_preferences_exist
|
|
29
37
|
|
|
30
38
|
# load player on-start
|
|
31
|
-
Aromancer::Api.set_active_legend_id(
|
|
39
|
+
Aromancer::Api.set_active_legend_id(
|
|
40
|
+
({} || Aromancer::Storage.get_player)[:active_legend_id.to_s]
|
|
41
|
+
) unless Aromancer::Storage.get_player.nil?
|
|
32
42
|
|
|
33
|
-
Thread.main[:route] = :authentication
|
|
34
|
-
Thread.main[:menu_runners] = {}
|
|
35
|
-
Thread.main[:menu_options] = {}
|
|
36
43
|
Aromancer::Prompt.say(I18n.t("shared.welcome", version: Aromancer::VERSION))
|
|
37
|
-
|
|
44
|
+
|
|
38
45
|
self.instance.start_ui_thread
|
|
39
46
|
self.instance.start_ws_thread
|
|
40
47
|
loop do
|
|
41
48
|
begin
|
|
49
|
+
|
|
50
|
+
if self.instance.should_clear_cache
|
|
51
|
+
Aromancer::Storage.instance.clear_cache!
|
|
52
|
+
self.instance.should_clear_cache = false
|
|
53
|
+
end
|
|
54
|
+
|
|
42
55
|
self.instance.ui_thread.join
|
|
56
|
+
|
|
43
57
|
rescue NoMethodError => e
|
|
58
|
+
Aromancer::Storage.set_last_error({
|
|
59
|
+
status: -1,
|
|
60
|
+
headers: e.to_s,
|
|
61
|
+
body: e.inspect.to_s
|
|
62
|
+
})
|
|
44
63
|
if Aromancer::Storage.get_preference(:debug)
|
|
45
64
|
Aromancer::Prompt.say(I18n.t("shared.last_error"))
|
|
46
|
-
Aromancer::Prompt.say(
|
|
47
|
-
|
|
48
|
-
sleep(5)
|
|
65
|
+
Aromancer::Prompt.say("sleeping 1 on main thread...")
|
|
66
|
+
sleep(1)
|
|
49
67
|
end
|
|
68
|
+
Aromancer::Storage.instance.clear_cache!
|
|
50
69
|
self.instance.start_ui_thread
|
|
51
70
|
self.instance.start_ws_thread
|
|
52
71
|
sleep(1)
|
|
@@ -76,11 +95,10 @@ module Aromancer
|
|
|
76
95
|
menu_runners.empty?
|
|
77
96
|
|
|
78
97
|
Aromancer::Routes.resume
|
|
79
|
-
sleep(
|
|
98
|
+
sleep(Aromancer::Cli::RENDER_DELAY)
|
|
80
99
|
Aromancer.print_hud
|
|
81
100
|
|
|
82
101
|
v = Aromancer::Prompt.p.select("", menu_options, show_help: :always, cycle: true, per_page: 11)
|
|
83
|
-
Aromancer.print_hud
|
|
84
102
|
runners = menu_runners.select{|r| r[:value] == v}
|
|
85
103
|
runners = menu_runners.select{|r| r[:value].nil?} if runners.empty?
|
|
86
104
|
|
|
@@ -90,12 +108,13 @@ module Aromancer
|
|
|
90
108
|
end
|
|
91
109
|
|
|
92
110
|
else
|
|
93
|
-
sleep(
|
|
111
|
+
sleep(Aromancer::Cli::RENDER_DELAY)
|
|
94
112
|
Aromancer::Routes.resume
|
|
113
|
+
Aromancer.print_hud
|
|
95
114
|
end
|
|
96
115
|
Aromancer::Cli.instance.ui_busy = false
|
|
97
116
|
Aromancer::Cli.instance.last_render = Time.now
|
|
98
|
-
sleep(
|
|
117
|
+
sleep(Aromancer::Cli::RENDER_DELAY)
|
|
99
118
|
end
|
|
100
119
|
end
|
|
101
120
|
end
|
|
@@ -121,12 +140,12 @@ module Aromancer
|
|
|
121
140
|
Aromancer::Websocket.instance.connect
|
|
122
141
|
if Aromancer::Storage.get_arena.nil?
|
|
123
142
|
Aromancer::Api.load_arena
|
|
124
|
-
sleep(
|
|
143
|
+
sleep(Aromancer::Cli::RENDER_DELAY)
|
|
125
144
|
Aromancer::Cli.instance.start_ui_thread(true)
|
|
126
145
|
end
|
|
127
146
|
end
|
|
128
147
|
@ws_busy = false
|
|
129
|
-
sleep(
|
|
148
|
+
sleep(Aromancer::Cli::RENDER_DELAY)
|
|
130
149
|
end
|
|
131
150
|
end
|
|
132
151
|
end
|
data/lib/aromancer/routes.rb
CHANGED
|
@@ -122,7 +122,7 @@ module Aromancer
|
|
|
122
122
|
Aromancer::Storage.instance.set_key(storage_key, previous)
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
-
Aromancer::
|
|
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(
|
|
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(
|
|
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{
|
|
227
|
-
{value: :find, proc: Proc.new{
|
|
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
|
}},
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
334
|
-
|
|
335
|
-
recent_count.nil? ?
|
|
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
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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.
|
|
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(
|
|
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
|
|
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
|
-
|
|
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.
|
|
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(
|
|
655
|
+
sleep(Aromancer::Cli::RENDER_DELAY)
|
|
650
656
|
}},
|
|
651
657
|
{value: nil, proc: Proc.new{|o|
|
|
652
|
-
Aromancer::Prompt.say(I18n.t("shared.
|
|
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(
|
|
665
|
+
sleep(Aromancer::Cli::RENDER_DELAY)
|
|
660
666
|
}}
|
|
661
667
|
]
|
|
662
668
|
Thread.main[:route_params] = [selected_word_id]
|
data/lib/aromancer/server.rb
CHANGED
|
@@ -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
|
|
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(
|
data/lib/aromancer/storage.rb
CHANGED
|
@@ -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.
|
|
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,
|
|
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
|
-
|
|
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, "
|
|
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({
|
|
134
|
+
f.write({created_at: Time.now}.to_json)
|
|
136
135
|
end
|
|
136
|
+
else
|
|
137
|
+
|
|
137
138
|
end
|
|
138
139
|
|
|
139
140
|
filepath
|
|
@@ -201,6 +202,7 @@ module Aromancer
|
|
|
201
202
|
|
|
202
203
|
def self.set_arena(arena_hash)
|
|
203
204
|
instance.set_key(:arena, arena_hash)
|
|
205
|
+
Aromancer::UnixDom.render_arena
|
|
204
206
|
end
|
|
205
207
|
|
|
206
208
|
def self.get_arena
|
|
@@ -230,12 +232,12 @@ module Aromancer
|
|
|
230
232
|
instance.set_key("server_url_#{k}", uri.select(k).first)
|
|
231
233
|
}
|
|
232
234
|
elsif get_server_url.nil?
|
|
233
|
-
set_server_url(
|
|
235
|
+
set_server_url(DEFAULT_SERVER_URL)
|
|
234
236
|
end
|
|
235
237
|
end
|
|
236
238
|
|
|
237
239
|
def self.get_server_url
|
|
238
|
-
set_server_url(
|
|
240
|
+
set_server_url(DEFAULT_SERVER_URL) if URI_KEYS.all?{|k| Aromancer::Storage.instance.get_key("server_url_#{k}").nil?}
|
|
239
241
|
URI.parse(URI_KEYS.map{|k|
|
|
240
242
|
c = Aromancer::Storage.instance.get_key("server_url_#{k}")
|
|
241
243
|
case k
|
|
@@ -269,101 +271,104 @@ module Aromancer
|
|
|
269
271
|
end
|
|
270
272
|
|
|
271
273
|
def get_key(key)
|
|
272
|
-
|
|
274
|
+
Aromancer::Cli.instance.storage_mutex.synchronize do
|
|
275
|
+
key = key.to_s
|
|
273
276
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
277
|
+
# ensure default for key exists
|
|
278
|
+
@cache[key] = {value: nil, persisted: false} unless @cache.keys.include?(key)
|
|
279
|
+
if false && (@cache[:preference_debug.to_s] || {value: DEFAULT_PREFERENCES[:preference_debug]})[:value]
|
|
280
|
+
Aromancer::Prompt.say("#{__method__} > @cache[#{key}]=#{@cache[key]}")
|
|
281
|
+
end
|
|
282
|
+
# return cache value if storage open or the cache value is persisted
|
|
283
|
+
return @cache[key][:value] if @storage_open || @cache[key][:persisted]
|
|
284
|
+
|
|
285
|
+
# open storage
|
|
286
|
+
@storage_open = true
|
|
287
|
+
storage_contents = {}
|
|
288
|
+
begin
|
|
289
|
+
@parser_error = nil
|
|
290
|
+
# read storage
|
|
291
|
+
storage_contents = JSON.parse(File.read(Aromancer::Storage.storage_filepath, encoding: "UTF-8"))
|
|
292
|
+
rescue StandardError => e
|
|
293
|
+
@storage_open = false
|
|
294
|
+
if @parser_error.nil?
|
|
295
|
+
@parser_error = e
|
|
296
|
+
return get_key(key)
|
|
297
|
+
else
|
|
298
|
+
raise @parser_error
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# only update the cache value if present in storage
|
|
303
|
+
if storage_contents.keys.include?(key)
|
|
304
|
+
@cache[key] = {value: storage_contents[key], persisted: true}
|
|
294
305
|
else
|
|
295
|
-
|
|
306
|
+
@cache[key][:persisted] = false
|
|
296
307
|
end
|
|
297
|
-
end
|
|
298
308
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
@cache[key][:persisted] = false
|
|
309
|
+
value = @cache[key][:value]
|
|
310
|
+
@storage_open = false
|
|
311
|
+
clear_cache! if @clear_flag
|
|
312
|
+
return value
|
|
304
313
|
end
|
|
305
|
-
|
|
306
|
-
value = @cache[key][:value]
|
|
307
|
-
@storage_open = false
|
|
308
|
-
clear_cache! if @clear_flag
|
|
309
|
-
return value
|
|
310
314
|
end
|
|
311
315
|
|
|
312
316
|
def set_key(key, value)
|
|
313
|
-
|
|
317
|
+
Aromancer::Cli.instance.storage_mutex.synchronize do
|
|
318
|
+
key = key.to_s
|
|
314
319
|
|
|
315
|
-
|
|
316
|
-
|
|
320
|
+
# ensure default for key exists
|
|
321
|
+
@cache[key] = {value: value, persisted: false} unless @cache.keys.include?(key)
|
|
317
322
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
323
|
+
# assign new cache value and set persisted to false
|
|
324
|
+
@cache[key][:value] = value
|
|
325
|
+
@cache[key][:persisted] = false
|
|
321
326
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
327
|
+
if @storage_open && (@cache[:preference_debug.to_s] || {value: DEFAULT_PREFERENCES[:preference_debug]})[:value]
|
|
328
|
+
Aromancer::Prompt.say("#{__method__} > @cache[#{key}]=#{@cache[key]}")
|
|
329
|
+
end
|
|
330
|
+
# return if storage open
|
|
331
|
+
# non-persisted cache values update next cycle
|
|
332
|
+
return if @storage_open
|
|
333
|
+
|
|
334
|
+
# open storage
|
|
335
|
+
@storage_open = true
|
|
336
|
+
storage_contents = {}
|
|
337
|
+
begin
|
|
338
|
+
@parser_error = nil
|
|
339
|
+
# read storage
|
|
340
|
+
storage_contents = JSON.parse(File.read(Aromancer::Storage.storage_filepath, encoding: "UTF-8"))
|
|
341
|
+
rescue StandardError => e
|
|
342
|
+
@storage_open = false
|
|
343
|
+
if @parser_error.nil?
|
|
344
|
+
@parser_error = e
|
|
345
|
+
return get_key(key)
|
|
346
|
+
else
|
|
347
|
+
raise @parser_error
|
|
348
|
+
end
|
|
344
349
|
end
|
|
345
|
-
end
|
|
346
350
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
351
|
+
# update storage and cache
|
|
352
|
+
([key] + @cache.keys.select{|k|
|
|
353
|
+
!@cache[k][:persisted]
|
|
354
|
+
}).each{|k|
|
|
355
|
+
storage_contents[k] = @cache[k][:value]
|
|
356
|
+
@cache[k][:persisted] = true
|
|
357
|
+
}
|
|
354
358
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
+
# write storage
|
|
360
|
+
File.open(Aromancer::Storage.storage_filepath, "w+") do |f|
|
|
361
|
+
f.write(storage_contents.to_json)
|
|
362
|
+
end
|
|
359
363
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
364
|
+
if (@cache[:preference_debug.to_s] || {value: DEFAULT_PREFERENCES[:preference_debug]})[:value]
|
|
365
|
+
Aromancer::Prompt.say("#{__method__} > @cache[#{key}]=#{@cache[key]}")
|
|
366
|
+
end
|
|
363
367
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
368
|
+
# close storage
|
|
369
|
+
@storage_open = false
|
|
370
|
+
clear_cache! if @clear_flag
|
|
371
|
+
end
|
|
367
372
|
end
|
|
368
373
|
end
|
|
369
374
|
end
|
data/lib/aromancer/version.rb
CHANGED
data/lib/aromancer/websocket.rb
CHANGED
|
@@ -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::
|
|
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,10 +28,26 @@ 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
|
+
FileUtils.mkdir_p(Aromancer.arena_directory) unless Dir.exist? Aromancer.arena_directory
|
|
34
|
+
unless Dir.exist? File.join(Aromancer.home_directory, :".git".to_s)
|
|
35
|
+
FileUtils.chdir Aromancer.home_directory do
|
|
36
|
+
system(:"git init".to_s)
|
|
37
|
+
system(:"git add .".to_s)
|
|
38
|
+
system(:"git commit -m \"#{self.name} initial commit\"".to_s)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
31
43
|
def self.home_directory
|
|
32
44
|
"#{`echo $HOME`.strip}/.aromancer"
|
|
33
45
|
end
|
|
34
46
|
|
|
47
|
+
def self.arena_directory
|
|
48
|
+
File.join(home_directory, :arena.to_s)
|
|
49
|
+
end
|
|
50
|
+
|
|
35
51
|
def self.date_display(raw)
|
|
36
52
|
DateTime.parse(raw)&.strftime(Aromancer::DATE_FORMAT).downcase.gsub(" ", "_")
|
|
37
53
|
end
|
|
@@ -51,9 +67,33 @@ module Aromancer
|
|
|
51
67
|
else
|
|
52
68
|
I18n.t("shared.signed_in_as", as: Aromancer::Storage.get_player["alias"])
|
|
53
69
|
end
|
|
70
|
+
server_status = I18n.t("shared.server_url", url: Aromancer::Storage::get_server_url)
|
|
71
|
+
force_ssl_value = Aromancer::Storage.get_preference(:force_ssl)
|
|
72
|
+
force_ssl_status_symbol = (
|
|
73
|
+
force_ssl_value
|
|
74
|
+
) ? UNICODE[:check] : UNICODE[:close]
|
|
75
|
+
force_ssl_status = "ssl: #{force_ssl_status_symbol}"
|
|
76
|
+
|
|
77
|
+
debug_value = Aromancer::Storage.get_preference(:debug)
|
|
78
|
+
hud = [
|
|
79
|
+
nil,
|
|
80
|
+
player_status,
|
|
81
|
+
server_status,
|
|
82
|
+
force_ssl_status,
|
|
83
|
+
websocket_status,
|
|
84
|
+
:v.to_s + Aromancer::VERSION,
|
|
85
|
+
nil
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
if debug_value
|
|
89
|
+
debug_status_symbol = (
|
|
90
|
+
debug_value
|
|
91
|
+
) ? UNICODE[:check] : UNICODE[:close]
|
|
92
|
+
hud.insert(1, "d: #{debug_status_symbol}")
|
|
93
|
+
end
|
|
54
94
|
|
|
55
95
|
Aromancer::Prompt.say(
|
|
56
|
-
|
|
96
|
+
hud.join(" | ")
|
|
57
97
|
)
|
|
58
98
|
end
|
|
59
99
|
|
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
|
|
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
|
-
|
|
16
|
+
spelling: "spelling..."
|
|
17
17
|
back: "back"
|
|
18
18
|
exit: "exit"
|
|
19
19
|
routes:
|
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.
|
|
4
|
+
version: 0.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- i2097i
|
|
@@ -248,6 +248,7 @@ files:
|
|
|
248
248
|
- checksums/aromancer-0.0.6.gem.sha512
|
|
249
249
|
- checksums/aromancer-0.0.7.gem.sha512
|
|
250
250
|
- checksums/aromancer-0.0.8.gem.sha512
|
|
251
|
+
- checksums/aromancer-0.0.9.gem.sha512
|
|
251
252
|
- lib/aromancer.rb
|
|
252
253
|
- lib/aromancer/.DS_Store
|
|
253
254
|
- lib/aromancer/api.rb
|
|
@@ -257,12 +258,12 @@ files:
|
|
|
257
258
|
- lib/aromancer/serve.rb
|
|
258
259
|
- lib/aromancer/server.rb
|
|
259
260
|
- lib/aromancer/storage.rb
|
|
261
|
+
- lib/aromancer/unix_dom.rb
|
|
260
262
|
- lib/aromancer/version.rb
|
|
261
263
|
- lib/aromancer/websocket.rb
|
|
262
264
|
- lib/reiquire.rb
|
|
263
265
|
- listen.rb
|
|
264
266
|
- locale/en.yml
|
|
265
|
-
- pre-commit.git.template
|
|
266
267
|
- sig/aromancer.rbs
|
|
267
268
|
- tasks/console.rake
|
|
268
269
|
- tasks/make.rake
|