aro 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/.release +20 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +105 -0
- data/LICENSE +21 -0
- data/README.md +70 -0
- data/Rakefile +5 -0
- data/aro.gemspec +30 -0
- data/bin/aro +7 -37
- data/bin/cli/config.rb +223 -0
- data/bin/cli/constants.rb +4 -2
- data/bin/cli/create.rb +8 -3
- data/bin/cli/deck.rb +63 -42
- data/bin/cli.rb +39 -0
- data/checksums/aro-0.1.4.gem.sha512 +1 -0
- data/lib/aro/create.rb +18 -19
- data/lib/aro/{database.rb → db.rb} +22 -28
- data/lib/aro/i18n.rb +8 -10
- data/lib/aro/prompt.rb +4 -0
- data/lib/aro/version.rb +2 -2
- data/lib/aro.rb +10 -7
- data/lib/models/deck.rb +124 -57
- data/lib/models/log.rb +8 -1
- data/locale/en.usage.yml +33 -10
- data/locale/en.yml +50 -14
- data/pkg/aro-0.1.0.gem +0 -0
- data/pkg/aro-0.1.1.gem +0 -0
- data/pkg/aro-0.1.2.gem +0 -0
- data/pkg/aro-0.1.3.gem +0 -0
- data/pkg/aro-0.1.4.gem +0 -0
- data/tasks/console.rake +8 -0
- data/tasks/make.rake +4 -0
- metadata +22 -22
data/bin/cli/deck.rb
CHANGED
|
@@ -17,63 +17,84 @@ module CLI
|
|
|
17
17
|
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
18
18
|
elsif CLI::ARGV1.nil?
|
|
19
19
|
# no args, open deck menu
|
|
20
|
-
Aro::Create.new(Aro::
|
|
20
|
+
Aro::Create.new(Aro::Db.get_name_from_namefile)
|
|
21
21
|
Aro::Deck.display_selection_menu
|
|
22
22
|
elsif action == CLI::CREATE_DECK_ACTIONS[:CREATE]
|
|
23
|
-
|
|
23
|
+
CLI::Aroface.exit_error_missing_args! if CLI::ARGV2.nil?
|
|
24
24
|
deck = Aro::Deck.make(CLI::ARGV2.to_s)
|
|
25
|
-
Aro::P.
|
|
25
|
+
Aro::P.say(I18n.t("cli.messages.deck_created_sucessfully", name: Aro::Mancy.game.name))
|
|
26
26
|
Aro::Deck.display_selection_menu
|
|
27
|
-
elsif CLI::LOAD_DECK_ACTIONS.include?(action)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else
|
|
33
|
-
# assume shuffle or show, in which case show is always called
|
|
34
|
-
if action == CLI::LOAD_DECK_ACTIONS[:SHUFFLE]
|
|
35
|
-
Aro::P.p.say(I18n.t("cli.messages.shuffling", name: deck.name))
|
|
36
|
-
deck.shuffle
|
|
37
|
-
elsif action == CLI::LOAD_DECK_ACTIONS[:DRAW]
|
|
38
|
-
Aro::P.p.say(I18n.t("cli.messages.drawing", name: deck.name))
|
|
39
|
-
deck.draw
|
|
40
|
-
elsif action == CLI::LOAD_DECK_ACTIONS[:REPLACE]
|
|
41
|
-
Aro::P.p.say(I18n.t("cli.messages.replacing_drawn", name: deck.name))
|
|
42
|
-
deck.replace
|
|
43
|
-
elsif action == CLI::LOAD_DECK_ACTIONS[:RESET]
|
|
44
|
-
if Aro::AROYES != Aro::P.p.ask(I18n.t("cli.messages.confirmation_prompt", name: deck.name))
|
|
45
|
-
Aro::P.p.say(I18n.t("cli.messages.understood", name: deck.name))
|
|
46
|
-
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
47
|
-
end
|
|
27
|
+
elsif CLI::LOAD_DECK_ACTIONS.include?(action)
|
|
28
|
+
if Aro::Mancy.game.nil?
|
|
29
|
+
Aro::P.say(I18n.t("cli.errors.missing_deck"))
|
|
30
|
+
exit(CLI::EXIT_CODES[:GENERAL_ERROR])
|
|
31
|
+
end
|
|
48
32
|
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
case action
|
|
34
|
+
when CLI::LOAD_DECK_ACTIONS[:EXPLORE]
|
|
35
|
+
Aro::Mancy.game.explore
|
|
36
|
+
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
37
|
+
when CLI::LOAD_DECK_ACTIONS[:SHUFFLE]
|
|
38
|
+
Aro::P.say(I18n.t("cli.messages.shuffling", name: Aro::Mancy.game.name))
|
|
39
|
+
Aro::Mancy.game.shuffle
|
|
40
|
+
when CLI::LOAD_DECK_ACTIONS[:DRAW]
|
|
41
|
+
Aro::P.say(I18n.t("cli.messages.drawing", name: Aro::Mancy.game.name))
|
|
42
|
+
Aro::P.p.say(I18n.t("cli.messages.drawing_from_dimension", dimension: "#{CLI::Config.var_value_with_suffix(:DIMENSION)}"))
|
|
43
|
+
Aro::Mancy.game.draw(
|
|
44
|
+
is_dt_dimension: CLI::Config.var_value_with_suffix(:DIMENSION).to_sym == CLI::Config::DMS[:DEV_TAROT],
|
|
45
|
+
z_max: CLI::Config.var_value_with_suffix(:Z_MAX).to_i,
|
|
46
|
+
z: CLI::Config.var_value_with_suffix(:Z)
|
|
47
|
+
)
|
|
48
|
+
when CLI::LOAD_DECK_ACTIONS[:REPLACE]
|
|
49
|
+
Aro::P.say(I18n.t("cli.messages.replacing_drawn", name: Aro::Mancy.game.name))
|
|
50
|
+
Aro::Mancy.game.replace
|
|
51
|
+
when CLI::LOAD_DECK_ACTIONS[:RESET]
|
|
52
|
+
if Aro::AROYES != Aro::P.p.ask(I18n.t("cli.messages.confirmation_prompt", name: Aro::Mancy.game.name))
|
|
53
|
+
Aro::P.say(I18n.t("cli.messages.understood", name: Aro::Mancy.game.name))
|
|
54
|
+
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
51
55
|
end
|
|
52
56
|
|
|
53
|
-
Aro::P.
|
|
54
|
-
|
|
57
|
+
Aro::P.say(I18n.t("cli.messages.resetting", name: Aro::Mancy.game.name))
|
|
58
|
+
Aro::Mancy.game.reset
|
|
55
59
|
end
|
|
60
|
+
|
|
61
|
+
Aro::Mancy.game.show(**CLI::Deck.shoptions)
|
|
56
62
|
else
|
|
57
63
|
CLI::usage
|
|
58
64
|
end
|
|
59
65
|
end
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
module Deck
|
|
68
|
+
|
|
69
|
+
# parse show options
|
|
70
|
+
def self.shoptions
|
|
71
|
+
show_options_count = Aro::Log::DEFAULT_COUNT
|
|
72
|
+
show_options_order = Aro::Log::ORDERING[:DESC]
|
|
73
|
+
|
|
74
|
+
# Aro::P.say("ARGV.map{|a| a.to_sym} => #{ARGV.map{|a| a.to_sym}}")
|
|
75
|
+
|
|
76
|
+
count_option_flags = ARGV.map{|a| a.to_sym} & CLI::FLAGS[:SHOW_COUNT]
|
|
77
|
+
# Aro::P.say("count_option_flags: #{count_option_flags}")
|
|
78
|
+
if count_option_flags.any?
|
|
79
|
+
# get the ARGV index element after flag index
|
|
80
|
+
show_options_count = ARGV[ARGV.index(count_option_flags.first.to_s) + 1]
|
|
81
|
+
show_options_count = show_options_count.to_i unless [0, nil].include?(show_options_count&.to_i)
|
|
82
|
+
# Aro::P.say("show_options_count: #{show_options_count}")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
order_option_flags = ARGV.map{|a| a.to_sym} & CLI::FLAGS[:SHOW_ORDER]
|
|
86
|
+
# Aro::P.say("count_option_flags: #{order_option_flags}")
|
|
87
|
+
if order_option_flags.any?
|
|
88
|
+
# get the ARGV index element after flag index
|
|
89
|
+
show_options_order = ARGV[ARGV.index(order_option_flags.first.to_s) + 1].upcase.to_sym
|
|
90
|
+
Aro::P.say("show_options_order: #{show_options_order}")
|
|
91
|
+
end
|
|
71
92
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
93
|
+
{
|
|
94
|
+
count_n: show_options_count,
|
|
95
|
+
order_o: show_options_order
|
|
96
|
+
}
|
|
75
97
|
end
|
|
76
98
|
|
|
77
|
-
deck
|
|
78
99
|
end
|
|
79
100
|
end
|
data/bin/cli.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require :aro.to_s
|
|
2
|
+
[:cli].each do |dir|
|
|
3
|
+
Dir[
|
|
4
|
+
File.join(
|
|
5
|
+
__dir__,
|
|
6
|
+
dir.to_s,
|
|
7
|
+
:"**/*.rb".to_s
|
|
8
|
+
)
|
|
9
|
+
].each { |file| require file}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# set environment variable
|
|
13
|
+
ENV[:ARO_ENV.to_s] = :production.to_s
|
|
14
|
+
# ENV[:ARO_ENV.to_s] = :development.to_s
|
|
15
|
+
|
|
16
|
+
module CLI
|
|
17
|
+
if CLI::LOAD_DECK_ACTIONS.keys.map{|k| k.downcase.to_sym}.include?(ARGV[0]&.to_sym)
|
|
18
|
+
# enable deck shortcut (skip typing deck while in-game)
|
|
19
|
+
ARGV0 = :deck
|
|
20
|
+
ARGV1 = ARGV[0]&.to_sym
|
|
21
|
+
ARGV2 = ARGV[1]&.to_sym
|
|
22
|
+
else
|
|
23
|
+
# default
|
|
24
|
+
ARGV0 = ARGV[0]&.to_sym
|
|
25
|
+
ARGV1 = ARGV[1]&.to_sym
|
|
26
|
+
ARGV2 = ARGV[2]&.to_sym
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class Aroface
|
|
30
|
+
|
|
31
|
+
def self.exit_error_missing_args!
|
|
32
|
+
Aro::P.say(I18n.t("cli.errors.header"))
|
|
33
|
+
Aro::P.say(I18n.t("cli.errors.missing_args", cmd: "#{CLI::ARGV0} #{CLI::ARGV1} #{CLI::ARGV2}".strip))
|
|
34
|
+
exit(CLI::EXIT_CODES[:INVALID_ARG])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
5a6af41ca8e0e2eee62a129aca162bc709d5c3ded0c4ec7b6326fa6768d949313f320bd659cf00d5a0056c1adced4898fdd6d9c91c2a79f7d06018cc9cc61ad7
|
data/lib/aro/create.rb
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
module Aro
|
|
2
2
|
class Create
|
|
3
|
-
|
|
4
|
-
name = name&.strip
|
|
3
|
+
attr_accessor :initialized
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
def initialize(name)
|
|
6
|
+
self.initialized = false
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
if !name.nil? && (
|
|
9
|
+
name.kind_of?(String) ||
|
|
10
|
+
name.kind_of?(Symbol)
|
|
11
|
+
)
|
|
12
|
+
# explicitly only allow String/Symbol types for name
|
|
13
|
+
name = name.to_s.strip
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
# create the new aro directory and database
|
|
16
|
+
if Aro::Db.get_name_from_namefile.nil? && !Dir.exist?(name)
|
|
17
|
+
Aro::P.say(I18n.t("cli.messages.no_decks"))
|
|
18
|
+
create_cmd = "mkdir #{name}"
|
|
19
|
+
Aro::P.say("#{create_cmd} (result: #{system(create_cmd)})")
|
|
20
|
+
end
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
create_cmd = "mkdir #{name}"
|
|
21
|
-
Aro::P.p.say(create_cmd)
|
|
22
|
-
system(create_cmd)
|
|
22
|
+
# create database
|
|
23
|
+
Aro::Db.new(name)
|
|
24
|
+
self.initialized = true
|
|
23
25
|
end
|
|
24
|
-
|
|
25
|
-
# create database
|
|
26
|
-
Aro::Database.new(name)
|
|
27
26
|
end
|
|
28
27
|
|
|
29
28
|
end
|
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
require :active_record.to_s
|
|
2
2
|
require :base64.to_s
|
|
3
3
|
require :yaml.to_s
|
|
4
|
+
require :fileutils.to_s
|
|
4
5
|
|
|
5
6
|
module Aro
|
|
6
|
-
class
|
|
7
|
+
class Db
|
|
7
8
|
CONFIG_FILE = "database.yml"
|
|
8
9
|
SQL_FILE = "database.sql"
|
|
9
10
|
SCHEMA_FILE = "schema.rb"
|
|
10
11
|
MIGRATIONS_DIR = "db/migrate"
|
|
11
|
-
NAME_FILE = ".name"
|
|
12
12
|
|
|
13
13
|
def initialize(name = nil)
|
|
14
14
|
# show queries in stout
|
|
15
15
|
ActiveRecord::Base.logger = Logger.new(STDOUT) if ENV[:ARO_ENV.to_s] == :development.to_s
|
|
16
16
|
|
|
17
17
|
# generate .name file
|
|
18
|
-
if name.nil? && Aro::
|
|
18
|
+
if name.nil? && Aro::Mancy.is_aro_dir?
|
|
19
19
|
# pwd is in aro directory, use name file
|
|
20
20
|
name = get_name_from_namefile
|
|
21
|
-
elsif !name.nil? && !Aro::
|
|
21
|
+
elsif !name.nil? && !Aro::Mancy.is_aro_dir?
|
|
22
22
|
# first use, pwd is not in aro directory yet
|
|
23
|
-
echo_cmd = "echo #{name} >> #{name}/#{NAME_FILE}"
|
|
24
|
-
Aro::P.
|
|
25
|
-
system(echo_cmd)
|
|
23
|
+
echo_cmd = "echo #{name} >> #{name}/#{Aro::Mancy::NAME_FILE}"
|
|
24
|
+
Aro::P.say("#{echo_cmd} (result: #{system(echo_cmd)})")
|
|
26
25
|
end
|
|
27
26
|
|
|
28
27
|
if name.nil?
|
|
@@ -41,44 +40,39 @@ module Aro
|
|
|
41
40
|
@config ||= YAML.load_file(db_config_filepath(name))
|
|
42
41
|
end
|
|
43
42
|
|
|
44
|
-
def base_aro_dir(name)
|
|
45
|
-
"#{Aro::
|
|
43
|
+
def self.base_aro_dir(name)
|
|
44
|
+
"#{Aro::Mancy.is_aro_dir? ? "." : name}/#{Aro::DIRS[:ARO].call}"
|
|
46
45
|
end
|
|
47
46
|
|
|
48
47
|
def db_config_filepath(name)
|
|
49
|
-
"#{base_aro_dir(name)}/#{CONFIG_FILE}"
|
|
48
|
+
"#{Aro::Db.base_aro_dir(name)}/#{CONFIG_FILE}"
|
|
50
49
|
end
|
|
51
50
|
|
|
52
51
|
def db_filepath(name)
|
|
53
|
-
"#{base_aro_dir(name)}/#{SQL_FILE}"
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def self.is_aro_dir?
|
|
57
|
-
File.exist?(NAME_FILE)
|
|
52
|
+
"#{Aro::Db.base_aro_dir(name)}/#{SQL_FILE}"
|
|
58
53
|
end
|
|
59
54
|
|
|
60
55
|
def self.get_name_from_namefile
|
|
61
|
-
Aro::
|
|
56
|
+
Aro::Mancy.is_aro_dir? ? File.read(Aro::Mancy::NAME_FILE).strip : nil
|
|
62
57
|
end
|
|
63
58
|
|
|
64
59
|
def setup_local_aro(name = nil, force = false)
|
|
65
60
|
# create local .aro/ directory
|
|
66
|
-
unless File.exist?(base_aro_dir(name)) || force
|
|
67
|
-
if File.exist?(base_aro_dir(name)) && force
|
|
68
|
-
rm_cmd = "rm -rf #{base_aro_dir(name)}"
|
|
69
|
-
Aro::P.
|
|
61
|
+
unless File.exist?(Aro::Db.base_aro_dir(name)) || force
|
|
62
|
+
if File.exist?(Aro::Db.base_aro_dir(name)) && force
|
|
63
|
+
rm_cmd = "rm -rf #{Aro::Db.base_aro_dir(name)}"
|
|
64
|
+
Aro::P.say(rm_cmd)
|
|
70
65
|
system(rm_cmd)
|
|
71
66
|
end
|
|
72
67
|
|
|
73
|
-
mk_cmd = "mkdir #{base_aro_dir(name)}"
|
|
74
|
-
Aro::P.
|
|
75
|
-
system(mk_cmd)
|
|
68
|
+
mk_cmd = "mkdir #{Aro::Db.base_aro_dir(name)}"
|
|
69
|
+
Aro::P.say("#{mk_cmd} (result: #{system(mk_cmd)})")
|
|
76
70
|
end
|
|
77
71
|
|
|
78
72
|
# create database config yaml file
|
|
79
73
|
c = {
|
|
80
74
|
adapter: :sqlite3.to_s,
|
|
81
|
-
database: "#{Aro::
|
|
75
|
+
database: "#{Aro::Db.base_aro_dir(name)}/#{SQL_FILE}",
|
|
82
76
|
username: name,
|
|
83
77
|
password: name
|
|
84
78
|
}.to_yaml
|
|
@@ -91,11 +85,11 @@ module Aro
|
|
|
91
85
|
end
|
|
92
86
|
|
|
93
87
|
def setup(name)
|
|
94
|
-
local_migrate_dir = "#{base_aro_dir(name)}/#{MIGRATIONS_DIR}"
|
|
88
|
+
local_migrate_dir = "#{Aro::Db.base_aro_dir(name)}/#{MIGRATIONS_DIR}"
|
|
95
89
|
unless Dir.exist?(local_migrate_dir)
|
|
96
90
|
gem_dir = Dir[Gem.loaded_specs[:aro.to_s]&.full_gem_path || '.'].first
|
|
97
|
-
cp_cmd = "cp -R #{gem_dir}/db #{base_aro_dir(name)}"
|
|
98
|
-
Aro::P.
|
|
91
|
+
cp_cmd = "cp -R #{gem_dir}/db #{Aro::Db.base_aro_dir(name)}"
|
|
92
|
+
Aro::P.say(cp_cmd)
|
|
99
93
|
system(cp_cmd)
|
|
100
94
|
end
|
|
101
95
|
|
|
@@ -104,7 +98,7 @@ module Aro
|
|
|
104
98
|
}.max
|
|
105
99
|
ActiveRecord::MigrationContext.new(local_migrate_dir).migrate(migration_version)
|
|
106
100
|
require 'active_record/schema_dumper'
|
|
107
|
-
filename = "#{base_aro_dir(name)}/#{SCHEMA_FILE}"
|
|
101
|
+
filename = "#{Aro::Db.base_aro_dir(name)}/#{SCHEMA_FILE}"
|
|
108
102
|
File.open(filename, "w+") do |f|
|
|
109
103
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection_pool, f)
|
|
110
104
|
end
|
data/lib/aro/i18n.rb
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
1
|
require :i18n.to_s
|
|
4
2
|
|
|
5
3
|
module Aro
|
|
6
|
-
|
|
7
|
-
end
|
|
4
|
+
LOCALE_DIR = :locale
|
|
8
5
|
|
|
9
|
-
locale_path = Gem.loaded_specs[:aro.to_s]&.full_gem_path
|
|
10
|
-
if Aro::IS_TEST.call
|
|
11
|
-
|
|
12
|
-
end
|
|
13
|
-
I18n.load_path += Dir["#{locale_path}
|
|
14
|
-
I18n.default_locale = :en
|
|
6
|
+
locale_path = Gem.loaded_specs[:aro.to_s]&.full_gem_path
|
|
7
|
+
if Aro::IS_TEST.call
|
|
8
|
+
locale_path = Dir.pwd
|
|
9
|
+
end
|
|
10
|
+
I18n.load_path += Dir["#{locale_path}/#{LOCALE_DIR}/*.yml"]
|
|
11
|
+
I18n.default_locale = :en
|
|
12
|
+
end
|
data/lib/aro/prompt.rb
CHANGED
data/lib/aro/version.rb
CHANGED
data/lib/aro.rb
CHANGED
|
@@ -16,20 +16,23 @@ module Aro
|
|
|
16
16
|
|
|
17
17
|
attr_accessor :game
|
|
18
18
|
|
|
19
|
+
OS = 2
|
|
20
|
+
PS1 = Aro::Mancy.name
|
|
21
|
+
NAME_FILE = :".name".to_s
|
|
22
|
+
I2097I = :i2097i
|
|
23
|
+
|
|
19
24
|
def initialize
|
|
20
|
-
Aro::Create.new(Aro::
|
|
25
|
+
Aro::Create.new(Aro::Db.get_name_from_namefile)
|
|
21
26
|
self.game = Aro::Deck.current_deck
|
|
22
27
|
end
|
|
23
28
|
|
|
24
|
-
def self.exit_error_missing_args!
|
|
25
|
-
Aro::P.p.say(I18n.t("cli.errors.header"))
|
|
26
|
-
Aro::P.p.say(I18n.t("cli.errors.missing_args", cmd: "#{CLI::ARGV0} #{CLI::ARGV1} #{CLI::ARGV2}"))
|
|
27
|
-
exit(CLI::EXIT_CODES[:INVALID_ARG])
|
|
28
|
-
end
|
|
29
|
-
|
|
30
29
|
def self.game
|
|
31
30
|
Mancy.instance.game
|
|
32
31
|
end
|
|
32
|
+
|
|
33
|
+
def self.is_aro_dir?
|
|
34
|
+
File.exist?(Aro::Mancy::NAME_FILE)
|
|
35
|
+
end
|
|
33
36
|
end
|
|
34
37
|
end
|
|
35
38
|
|
data/lib/models/deck.rb
CHANGED
|
@@ -9,7 +9,7 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
9
9
|
DEV_TAROT_FILE = "/dev/tarot"
|
|
10
10
|
|
|
11
11
|
# update this for # of cards you will draw
|
|
12
|
-
DRAW_COUNT =
|
|
12
|
+
DRAW_COUNT = 7
|
|
13
13
|
|
|
14
14
|
# do not modify
|
|
15
15
|
DISPLAY_WIDTH = Aro::Deck::DRAW_COUNT*Aro::Deck::DRAW_COUNT
|
|
@@ -52,7 +52,7 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
52
52
|
|
|
53
53
|
def self.display_selection_menu
|
|
54
54
|
unless Aro::Deck.any?
|
|
55
|
-
Aro::P.
|
|
55
|
+
Aro::P.say(I18n.t("cli.messages.no_decks"))
|
|
56
56
|
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -76,27 +76,40 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
def self.read_dev_tarot
|
|
80
|
-
dt = nil
|
|
81
|
-
return dt unless File.exist?(Aro::Deck::DEV_TAROT_FILE)
|
|
82
|
-
|
|
83
|
-
File.open(Aro::Deck::DEV_TAROT_FILE, "r"){|dtf| dt = dtf.read(4)}
|
|
84
|
-
end
|
|
85
|
-
|
|
86
79
|
def self.card_strip(card)
|
|
87
80
|
card.gsub(/[+-]/, "").strip
|
|
88
81
|
end
|
|
89
82
|
|
|
90
|
-
def show
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
def show(count_n: Aro::Log::DEFAULT_COUNT, order_o: Aro::Log::ORDERING[:DESC])
|
|
84
|
+
unless count_n.kind_of?(Numeric) && count_n > 0
|
|
85
|
+
if count_n&.to_s&.downcase&.to_sym == Aro::Log::ALL
|
|
86
|
+
count_n = logs.count
|
|
87
|
+
else
|
|
88
|
+
count_n = Aro::Log::DEFAULT_COUNT
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
count_n = [count_n.to_i, logs.count].min
|
|
92
|
+
|
|
93
|
+
unless Aro::Log::ORDERING.include?(order_o&.to_s&.upcase&.to_sym)
|
|
94
|
+
Aro::P.say(I18n.t("cli.warnings.invalid_order"))
|
|
95
|
+
order_o = Aro::Log::ORDERING[:DESC]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# perform query
|
|
99
|
+
h_logs = logs.order(created_at: order_o.to_s.downcase).first(count_n)
|
|
100
|
+
|
|
101
|
+
# for now tests just expect text output
|
|
102
|
+
return h_logs if Aro::IS_TEST.call
|
|
103
|
+
|
|
104
|
+
Aro::P.say(I18n.t("cli.messages.showing", name: name, count: count_n, order: order_o))
|
|
105
|
+
|
|
106
|
+
h_text = "\n"
|
|
94
107
|
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n\n"
|
|
95
108
|
h_text += "#{name.upcase.center(Aro::Deck::DISPLAY_WIDTH)}\n\n"
|
|
96
|
-
|
|
109
|
+
h_logs.each_with_index{|l, i|
|
|
97
110
|
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
98
111
|
h_text += l.created_at.strftime(Aro::Deck::DATE_FORMAT).center(Aro::Deck::DISPLAY_WIDTH) + "\n"
|
|
99
|
-
h_text += "#{logs.count - i} of #{logs.count}".rjust(Aro::Deck::DISPLAY_WIDTH) + "\n"
|
|
112
|
+
h_text += "#{order_o.to_sym == Aro::Log::ORDERING[:DESC] ? logs.count - i : 1 + i} of #{logs.count}".rjust(Aro::Deck::DISPLAY_WIDTH) + "\n"
|
|
100
113
|
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n\n"
|
|
101
114
|
h_text += get_display_for_cards(
|
|
102
115
|
Base64::decode64(l.card_data).split(Aro::Deck::CARD_DELIM)
|
|
@@ -112,13 +125,19 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
112
125
|
drawn_cards
|
|
113
126
|
)
|
|
114
127
|
h_text += "\n"
|
|
128
|
+
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
115
129
|
end
|
|
116
|
-
}
|
|
117
130
|
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
3.times do
|
|
132
|
+
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
133
|
+
end
|
|
134
|
+
}
|
|
120
135
|
|
|
121
|
-
Aro::
|
|
136
|
+
if count_n == Aro::Log::DEFAULT_COUNT
|
|
137
|
+
Aro::P.say(h_text)
|
|
138
|
+
else
|
|
139
|
+
Aro::P.less(h_text)
|
|
140
|
+
end
|
|
122
141
|
end
|
|
123
142
|
|
|
124
143
|
def get_display_for_cards(input = []) # todo:, print_nums: false)
|
|
@@ -145,8 +164,7 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
145
164
|
default: 1
|
|
146
165
|
)
|
|
147
166
|
|
|
148
|
-
|
|
149
|
-
Aro::P.p.say(I18n.t("cards.#{Aro::Deck.card_strip(answer)}"))
|
|
167
|
+
Aro::P.say(I18n.t("cards.#{Aro::Deck.card_strip(answer)}"))
|
|
150
168
|
end
|
|
151
169
|
|
|
152
170
|
def shuffle
|
|
@@ -173,48 +191,97 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
173
191
|
update(drawn: "", cards: cards_arr.join(Aro::Deck::CARD_DELIM))
|
|
174
192
|
end
|
|
175
193
|
|
|
176
|
-
|
|
177
|
-
|
|
194
|
+
# read dev_tarot
|
|
195
|
+
def self.read_dev_tarot
|
|
196
|
+
dt = nil
|
|
197
|
+
return dt unless File.exist?(Aro::Deck::DEV_TAROT_FILE)
|
|
198
|
+
|
|
199
|
+
File.open(Aro::Deck::DEV_TAROT_FILE, "r"){|dtf| dt = dtf.read(4)}
|
|
200
|
+
|
|
201
|
+
# VERY IMPORTANT!
|
|
202
|
+
Aro::P.say(I18n.t("cli.very_important", dev_tarot: dt))
|
|
203
|
+
return dt
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# summon ruby_facot
|
|
207
|
+
def summon_ruby_facot(cards_arr)
|
|
208
|
+
Aro::P.say(I18n.t("cli.messages.ruby_facot_random"))
|
|
209
|
+
ruby_facot = cards_arr.sample.split("")
|
|
210
|
+
|
|
211
|
+
# get orientation
|
|
212
|
+
ruby_facot_str = ["+","-"].sample
|
|
213
|
+
|
|
214
|
+
# get suite
|
|
215
|
+
ruby_facot_str += ruby_facot[1]
|
|
216
|
+
|
|
217
|
+
# calculate the sym
|
|
218
|
+
symm = ruby_facot.select{|c|
|
|
219
|
+
# loops through the characters in ruby_facot
|
|
220
|
+
# return all characters not matching:
|
|
221
|
+
# => character[0]: orientation
|
|
222
|
+
# => character[1]: suite
|
|
223
|
+
|
|
224
|
+
# the first two characters in the dev_tarot format designate the
|
|
225
|
+
!ruby_facot.first(Aro::Mancy::OS).include?(c)
|
|
226
|
+
}.join("").to_sym
|
|
227
|
+
ruby_facot_str += Aro::NUMERALS[symm].to_s
|
|
228
|
+
|
|
229
|
+
# return ruby_facot_str
|
|
230
|
+
ruby_facot_str
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def draw(is_dt_dimension: true, z_max: 7, z: 1)
|
|
234
|
+
# the true card
|
|
235
|
+
abs_dev_tarot = nil
|
|
236
|
+
|
|
237
|
+
# oriented card
|
|
178
238
|
dev_tarot = nil
|
|
179
239
|
|
|
240
|
+
# get cards
|
|
241
|
+
cards_arr = cards.split(Aro::Deck::CARD_DELIM) || []
|
|
242
|
+
# get abs_cards
|
|
243
|
+
abs_cards_arr = cards_arr.map{|c| Aro::Deck.card_strip(c)}
|
|
244
|
+
# get drawn
|
|
245
|
+
drawn_arr = drawn&.split(Aro::Deck::CARD_DELIM) || []
|
|
246
|
+
|
|
247
|
+
# use fallback randomness if /dev/tarot unavailable
|
|
248
|
+
if !is_dt_dimension || !File.exist?(Aro::Deck::DEV_TAROT_FILE)
|
|
249
|
+
dev_tarot = summon_ruby_facot(cards_arr)
|
|
250
|
+
abs_dev_tarot = Aro::Deck.card_strip(dev_tarot)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
sleeps = 0
|
|
254
|
+
sleeps_max = z_max
|
|
255
|
+
|
|
180
256
|
# find a card that is not already drawn
|
|
181
|
-
while dev_tarot.nil? do
|
|
257
|
+
while sleeps <= sleeps_max && dev_tarot.nil? do
|
|
182
258
|
# preferred randomness
|
|
183
|
-
dev_tarot =
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
dev_tarot = (
|
|
193
|
-
facade.first(2).join("") +
|
|
194
|
-
Aro::NUMERALS[
|
|
195
|
-
facade.select{|c| !facade.first(2).include?(c)}.join("").to_sym
|
|
196
|
-
].to_s
|
|
197
|
-
).split("")
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
dev_tarot_converted = dev_tarot[1] + Aro::NUMERALS.key(
|
|
201
|
-
dev_tarot.select{|c| !dev_tarot.first(2).include?(c)}.join("").to_i
|
|
202
|
-
).to_s
|
|
203
|
-
if cards_arr_stripped.include?(dev_tarot_converted)
|
|
204
|
-
# dev_tarot is valid
|
|
205
|
-
drawn_arr = drawn&.split(Aro::Deck::CARD_DELIM) || []
|
|
206
|
-
dev_tarot = dev_tarot[0] + dev_tarot_converted
|
|
207
|
-
drawn_arr << dev_tarot
|
|
208
|
-
cards_arr.delete_at(cards_arr_stripped.index(dev_tarot_converted))
|
|
209
|
-
update(
|
|
210
|
-
cards: cards_arr.join(Aro::Deck::CARD_DELIM),
|
|
211
|
-
drawn: drawn_arr.join(Aro::Deck::CARD_DELIM)
|
|
212
|
-
)
|
|
259
|
+
dev_tarot = Aro::Deck.read_dev_tarot&.strip&.split("")
|
|
260
|
+
if dev_tarot.present?
|
|
261
|
+
abs_dev_tarot = dev_tarot[1] + Aro::NUMERALS.key(
|
|
262
|
+
dev_tarot.select{|c| !dev_tarot.first(2).include?(c)}.join("").to_i
|
|
263
|
+
).to_s
|
|
264
|
+
if abs_cards_arr.include?(abs_dev_tarot)
|
|
265
|
+
# dev_tarot is valid
|
|
266
|
+
dev_tarot = dev_tarot[0] + abs_dev_tarot
|
|
267
|
+
end
|
|
213
268
|
else
|
|
214
269
|
# dev_tarot is invalid
|
|
215
|
-
|
|
216
|
-
sleep(
|
|
270
|
+
sleeps += 1
|
|
271
|
+
sleep(z)
|
|
217
272
|
end
|
|
218
273
|
end
|
|
274
|
+
|
|
275
|
+
# remove from cards
|
|
276
|
+
cards_arr.delete(cards_arr.select{|c| c.include?(abs_dev_tarot)}.first)
|
|
277
|
+
|
|
278
|
+
# insert dev_tarot to drawn
|
|
279
|
+
drawn_arr << dev_tarot
|
|
280
|
+
|
|
281
|
+
# update database
|
|
282
|
+
update(
|
|
283
|
+
cards: cards_arr.join(Aro::Deck::CARD_DELIM),
|
|
284
|
+
drawn: drawn_arr.join(Aro::Deck::CARD_DELIM)
|
|
285
|
+
)
|
|
219
286
|
end
|
|
220
|
-
end
|
|
287
|
+
end
|
data/lib/models/log.rb
CHANGED