aro 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +5 -5
- data/.ruby-version +1 -1
- data/Gemfile.lock +32 -14
- data/aro.gemspec +17 -8
- data/bin/aos +19 -0
- data/bin/aro +24 -24
- data/checksums/aro-0.1.6.gem.sha512 +1 -0
- data/checksums/aro-0.1.7.gem.sha512 +1 -0
- data/checksums/aro-0.1.8.gem.sha512 +1 -0
- data/db/migrate/1763374647_create_decks.rb +3 -0
- data/db/migrate/1763432541_create_logs.rb +1 -0
- data/db/migrate/1765148774_create_yous.rb +19 -0
- data/listen.rb +10 -0
- data/locale/en.aos.yml +27 -0
- data/locale/en.cngelog.yml +5 -0
- data/locale/en.usage.yml +55 -38
- data/locale/en.yml +47 -15
- data/sys/aos/aos.rb +199 -0
- data/sys/aos/db.rb +81 -0
- data/sys/aos/s.rb +25 -0
- data/sys/aos/views/base.rb +139 -0
- data/sys/aos/views/dom.rb +45 -0
- data/sys/aos/views/games/abpps.rb +21 -0
- data/sys/aos/views/games/deck.rb +95 -0
- data/sys/aos/views/games/game.rb +24 -0
- data/sys/aos/views/games/hbpps.rb +21 -0
- data/sys/aos/views/games/shpps.rb +21 -0
- data/sys/aos/views/games/vipps.rb +21 -0
- data/sys/aos/views/games.rb +19 -0
- data/sys/aos/views/know/library.rb +19 -0
- data/sys/aos/views/know/temple.rb +19 -0
- data/sys/aos/views/know.rb +19 -0
- data/sys/aos/views/setup/settings.rb +50 -0
- data/sys/aos/views/setup.rb +19 -0
- data/sys/aos/views/welcome/waite.rb +19 -0
- data/sys/aos/views/welcome/winner.rb +19 -0
- data/sys/aos/views/welcome.rb +19 -0
- data/sys/aos/you.rb +15 -0
- data/sys/aro/d.rb +25 -0
- data/sys/aro/db.rb +89 -0
- data/sys/aro/mancy.rb +114 -0
- data/sys/aro/p.rb +25 -0
- data/sys/aro/r.rb +20 -0
- data/sys/aro/v.rb +24 -0
- data/sys/aro.rb +16 -0
- data/sys/cli/config.rb +582 -0
- data/sys/cli/constants.rb +56 -0
- data/{bin → sys}/cli/create.rb +6 -4
- data/sys/cli/deck.rb +98 -0
- data/sys/cli/dom.rb +37 -0
- data/sys/cli/nterface.rb +31 -0
- data/{bin → sys}/cli/usage.rb +1 -1
- data/sys/cli.rb +26 -0
- data/sys/dom/d.rb +101 -0
- data/sys/dom/dom.rb +161 -0
- data/sys/dom/p.rb +17 -0
- data/sys/models/deck.rb +218 -0
- data/sys/models/log.rb +20 -0
- data/sys/reiquire.rb +45 -0
- data/sys/shr/prompt.rb +37 -0
- data/sys/shr/t.rb +60 -0
- data/sys/shr/version.rb +16 -0
- data/tasks/make.rake +2 -2
- metadata +78 -22
- data/.release +0 -20
- data/bin/cli/config.rb +0 -231
- data/bin/cli/constants.rb +0 -39
- data/bin/cli/deck.rb +0 -100
- data/bin/cli.rb +0 -39
- data/lib/aro/c.rb +0 -32
- data/lib/aro/create.rb +0 -29
- data/lib/aro/db.rb +0 -107
- data/lib/aro/environment.rb +0 -3
- data/lib/aro/i18n.rb +0 -12
- data/lib/aro/prompt.rb +0 -25
- data/lib/aro/version.rb +0 -4
- data/lib/aro.rb +0 -45
- data/lib/models/deck.rb +0 -294
- data/lib/models/log.rb +0 -12
data/bin/cli/deck.rb
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
=begin
|
|
2
|
-
|
|
3
|
-
deck.rb
|
|
4
|
-
|
|
5
|
-
process deck commands.
|
|
6
|
-
|
|
7
|
-
by i2097i
|
|
8
|
-
|
|
9
|
-
=end
|
|
10
|
-
|
|
11
|
-
module CLI
|
|
12
|
-
def self.deck
|
|
13
|
-
action = CLI::ARGV1&.upcase&.to_sym
|
|
14
|
-
|
|
15
|
-
if CLI::FLAGS[:HELP].include?(CLI::ARGV1)
|
|
16
|
-
CLI::usage
|
|
17
|
-
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
18
|
-
elsif CLI::ARGV1.nil?
|
|
19
|
-
# no args, open deck menu
|
|
20
|
-
Aro::Create.new(Aro::Db.get_name_from_namefile)
|
|
21
|
-
Aro::Deck.display_selection_menu
|
|
22
|
-
elsif action == CLI::CREATE_DECK_ACTIONS[:CREATE]
|
|
23
|
-
CLI::Aroface.exit_error_missing_args! if CLI::ARGV2.nil?
|
|
24
|
-
deck = Aro::Deck.make(CLI::ARGV2.to_s)
|
|
25
|
-
Aro::P.say(I18n.t("cli.messages.deck_created_sucessfully", name: Aro::Mancy.game.name))
|
|
26
|
-
Aro::Deck.display_selection_menu
|
|
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
|
|
32
|
-
|
|
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.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.to_s != 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])
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
Aro::P.say(I18n.t("cli.messages.resetting", name: Aro::Mancy.game.name))
|
|
58
|
-
Aro::Mancy.game.reset
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
Aro::Mancy.game.show(**CLI::Deck.shoptions)
|
|
62
|
-
else
|
|
63
|
-
CLI::usage
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
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
|
|
92
|
-
|
|
93
|
-
{
|
|
94
|
-
count_n: show_options_count,
|
|
95
|
-
order_o: show_options_order
|
|
96
|
-
}
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
end
|
|
100
|
-
end
|
data/bin/cli.rb
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
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
|
data/lib/aro/c.rb
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
module Aro
|
|
2
|
-
DIRS = {
|
|
3
|
-
ARO: Proc.new{Aro::IS_TEST.call ? ".aro_test" : ".aro"},
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
AROYES = :aroyes
|
|
7
|
-
|
|
8
|
-
NUMERALS = {
|
|
9
|
-
O: 0,
|
|
10
|
-
I: 1,
|
|
11
|
-
II: 2,
|
|
12
|
-
III: 3,
|
|
13
|
-
IV: 4,
|
|
14
|
-
V: 5,
|
|
15
|
-
VI: 6,
|
|
16
|
-
VII: 7,
|
|
17
|
-
VIII: 8,
|
|
18
|
-
IX: 9,
|
|
19
|
-
X: 10,
|
|
20
|
-
XI: 11,
|
|
21
|
-
XII: 12,
|
|
22
|
-
XIII: 13,
|
|
23
|
-
XIV: 14,
|
|
24
|
-
XV: 15,
|
|
25
|
-
XVI: 16,
|
|
26
|
-
XVII: 17,
|
|
27
|
-
XVIII:18,
|
|
28
|
-
XIX: 19,
|
|
29
|
-
XX: 20,
|
|
30
|
-
XXI: 21,
|
|
31
|
-
}
|
|
32
|
-
end
|
data/lib/aro/create.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module Aro
|
|
2
|
-
class Create
|
|
3
|
-
attr_accessor :initialized
|
|
4
|
-
|
|
5
|
-
def initialize(name)
|
|
6
|
-
self.initialized = false
|
|
7
|
-
|
|
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
|
|
14
|
-
|
|
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
|
|
21
|
-
|
|
22
|
-
# create database
|
|
23
|
-
Aro::Db.new(name)
|
|
24
|
-
self.initialized = true
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
end
|
data/lib/aro/db.rb
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
require :active_record.to_s
|
|
2
|
-
require :base64.to_s
|
|
3
|
-
require :yaml.to_s
|
|
4
|
-
require :fileutils.to_s
|
|
5
|
-
|
|
6
|
-
module Aro
|
|
7
|
-
class Db
|
|
8
|
-
CONFIG_FILE = "database.yml"
|
|
9
|
-
SQL_FILE = "database.sql"
|
|
10
|
-
SCHEMA_FILE = "schema.rb"
|
|
11
|
-
MIGRATIONS_DIR = "db/migrate"
|
|
12
|
-
|
|
13
|
-
def initialize(name = nil)
|
|
14
|
-
# show queries in stout
|
|
15
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT) if ENV[:ARO_ENV.to_s] == :development.to_s
|
|
16
|
-
|
|
17
|
-
# generate .name file
|
|
18
|
-
if name.nil? && Aro::Mancy.is_aro_dir?
|
|
19
|
-
# pwd is in aro directory, use name file
|
|
20
|
-
name = get_name_from_namefile
|
|
21
|
-
elsif !name.nil? && !Aro::Mancy.is_aro_dir?
|
|
22
|
-
# first use, pwd is not in aro directory yet
|
|
23
|
-
echo_cmd = "echo #{name} >> #{name}/#{Aro::Mancy::NAME_FILE}"
|
|
24
|
-
Aro::P.say("#{echo_cmd} (result: #{system(echo_cmd)})")
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
if name.nil?
|
|
28
|
-
# if name is still nil, need to use create to generate aro directory
|
|
29
|
-
raise "invalid aro directory. use `aro create` to generate one"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
setup_local_aro(name)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def connect(name)
|
|
36
|
-
ActiveRecord::Base.establish_connection(config(name))
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def config(name = nil)
|
|
40
|
-
@config ||= YAML.load_file(db_config_filepath(name))
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def self.base_aro_dir(name)
|
|
44
|
-
"#{Aro::Mancy.is_aro_dir? ? "." : name}/#{Aro::DIRS[:ARO].call}"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def db_config_filepath(name)
|
|
48
|
-
"#{Aro::Db.base_aro_dir(name)}/#{CONFIG_FILE}"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def db_filepath(name)
|
|
52
|
-
"#{Aro::Db.base_aro_dir(name)}/#{SQL_FILE}"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def self.get_name_from_namefile
|
|
56
|
-
Aro::Mancy.is_aro_dir? ? File.read(Aro::Mancy::NAME_FILE).strip : nil
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def setup_local_aro(name = nil, force = false)
|
|
60
|
-
# create local .aro/ directory
|
|
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)
|
|
65
|
-
system(rm_cmd)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
mk_cmd = "mkdir #{Aro::Db.base_aro_dir(name)}"
|
|
69
|
-
Aro::P.say("#{mk_cmd} (result: #{system(mk_cmd)})")
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# create database config yaml file
|
|
73
|
-
c = {
|
|
74
|
-
adapter: :sqlite3.to_s,
|
|
75
|
-
database: "#{Aro::Db.base_aro_dir(name)}/#{SQL_FILE}",
|
|
76
|
-
username: name,
|
|
77
|
-
password: name
|
|
78
|
-
}.to_yaml
|
|
79
|
-
File.open(db_config_filepath(name), "w") do |file|
|
|
80
|
-
file.write(c)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
connect(name)
|
|
84
|
-
setup(name)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def setup(name)
|
|
88
|
-
local_migrate_dir = "#{Aro::Db.base_aro_dir(name)}/#{MIGRATIONS_DIR}"
|
|
89
|
-
unless Dir.exist?(local_migrate_dir)
|
|
90
|
-
gem_dir = Dir[Gem.loaded_specs[:aro.to_s]&.full_gem_path || '.'].first
|
|
91
|
-
cp_cmd = "cp -R #{gem_dir}/db #{Aro::Db.base_aro_dir(name)}"
|
|
92
|
-
Aro::P.say(cp_cmd)
|
|
93
|
-
system(cp_cmd)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
migration_version = Dir["#{local_migrate_dir}/*.rb"].map{|n|
|
|
97
|
-
Pathname.new(n).basename.to_s.split("_")[0].to_i
|
|
98
|
-
}.max
|
|
99
|
-
ActiveRecord::MigrationContext.new(local_migrate_dir).migrate(migration_version)
|
|
100
|
-
require 'active_record/schema_dumper'
|
|
101
|
-
filename = "#{Aro::Db.base_aro_dir(name)}/#{SCHEMA_FILE}"
|
|
102
|
-
File.open(filename, "w+") do |f|
|
|
103
|
-
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection_pool, f)
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
data/lib/aro/environment.rb
DELETED
data/lib/aro/i18n.rb
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
require :i18n.to_s
|
|
2
|
-
|
|
3
|
-
module Aro
|
|
4
|
-
LOCALE_DIR = :locale
|
|
5
|
-
|
|
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
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require :"tty-prompt".to_s
|
|
2
|
-
|
|
3
|
-
module Aro
|
|
4
|
-
class P
|
|
5
|
-
include Singleton
|
|
6
|
-
|
|
7
|
-
attr_accessor :prompt
|
|
8
|
-
|
|
9
|
-
def initialize
|
|
10
|
-
self.prompt = TTY::Prompt.new
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.p
|
|
14
|
-
P.instance.prompt
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def self.say(message)
|
|
18
|
-
Aro::P::p.say(">[#{Aro::Mancy::PS1}::#{Time.now.to_i}]>: #{message}")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def self.less(display_text = "")
|
|
22
|
-
IO.popen("less -X", "w") { |f| f.puts display_text }
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
data/lib/aro/version.rb
DELETED
data/lib/aro.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# require aro directories
|
|
2
|
-
[
|
|
3
|
-
:aro,
|
|
4
|
-
:models,
|
|
5
|
-
].each{|dir|
|
|
6
|
-
Dir[File.join(
|
|
7
|
-
__dir__,
|
|
8
|
-
dir.to_s,
|
|
9
|
-
:"**/*.rb".to_s
|
|
10
|
-
)].each { |file| require file}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module Aro
|
|
14
|
-
class Mancy
|
|
15
|
-
include Singleton
|
|
16
|
-
|
|
17
|
-
attr_accessor :game
|
|
18
|
-
|
|
19
|
-
O = 0
|
|
20
|
-
S = 1
|
|
21
|
-
N = 4
|
|
22
|
-
OS = 2
|
|
23
|
-
PS1 = Aro::Mancy.name
|
|
24
|
-
NAME_FILE = :".name".to_s
|
|
25
|
-
I2097I = :i2097i
|
|
26
|
-
|
|
27
|
-
def initialize
|
|
28
|
-
Aro::Create.new(Aro::Db.get_name_from_namefile)
|
|
29
|
-
self.game = Aro::Deck.current_deck
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def self.game
|
|
33
|
-
Mancy.instance.game
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def self.is_aro_dir?
|
|
37
|
-
File.exist?(Aro::Mancy::NAME_FILE)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# TODO: this doesn't work
|
|
43
|
-
# require :"active_support/time_with_zone".to_s
|
|
44
|
-
# TODO: this doesn't work
|
|
45
|
-
# Time.zone = ActiveSupport::TimeZone[Time.now.gmtoff].tzinfo.name
|
data/lib/models/deck.rb
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
require :base64.to_s
|
|
2
|
-
require_relative :"./log".to_s
|
|
3
|
-
|
|
4
|
-
class Aro::Deck < ActiveRecord::Base
|
|
5
|
-
has_many :logs
|
|
6
|
-
|
|
7
|
-
DECK_FILE = ".deck"
|
|
8
|
-
CARD_DELIM = ","
|
|
9
|
-
DEV_TAROT_FILE = "/dev/tarot"
|
|
10
|
-
|
|
11
|
-
# update this for # of cards you will draw
|
|
12
|
-
DRAW_COUNT = 7
|
|
13
|
-
|
|
14
|
-
# do not modify
|
|
15
|
-
DISPLAY_WIDTH = Aro::Deck::DRAW_COUNT*Aro::Deck::DRAW_COUNT
|
|
16
|
-
HISTORY_SEPARATOR = "#{"-" * Aro::Deck::DISPLAY_WIDTH}"
|
|
17
|
-
|
|
18
|
-
# change to update how timestamps appear
|
|
19
|
-
DATE_FORMAT = "%Y:%m:%d:%H:%M:%S"
|
|
20
|
-
|
|
21
|
-
before_create :populate_cards
|
|
22
|
-
after_commit :generate_log
|
|
23
|
-
|
|
24
|
-
def self.make(new_name)
|
|
25
|
-
Aro::Create.new(new_name)
|
|
26
|
-
new_deck = Aro::Deck.create(name: new_name)
|
|
27
|
-
if Aro::Deck.current_deck.nil?
|
|
28
|
-
File.open(Aro::Deck::DECK_FILE, "w") do |file|
|
|
29
|
-
file.write(new_deck.id)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
new_deck
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def self.fresh_cards
|
|
36
|
-
I18n.t("cards.index").map{|c| "+#{c}"}.join(Aro::Deck::CARD_DELIM)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def populate_cards
|
|
40
|
-
self.cards = Aro::Deck.fresh_cards
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def generate_log
|
|
44
|
-
prev_cards = Base64::decode64(logs.last.card_data) if logs.any?
|
|
45
|
-
if prev_cards.present? && prev_cards != cards || prev_cards.nil?
|
|
46
|
-
logs.create(
|
|
47
|
-
card_data: Base64::encode64(cards),
|
|
48
|
-
drawn_data: Base64::encode64(drawn || "")
|
|
49
|
-
)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def self.display_selection_menu
|
|
54
|
-
unless Aro::Deck.any?
|
|
55
|
-
Aro::P.say(I18n.t("cli.messages.no_decks"))
|
|
56
|
-
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
selection = Aro::P.p.select("choose a deck:") do |menu|
|
|
60
|
-
Aro::Deck.all.each{|d|
|
|
61
|
-
if d.id == Aro::Deck.current_deck&.id
|
|
62
|
-
menu.default d.id
|
|
63
|
-
end
|
|
64
|
-
menu.choice(d.name, d.id)
|
|
65
|
-
}
|
|
66
|
-
end
|
|
67
|
-
File.open(Aro::Deck::DECK_FILE, "w") do |file|
|
|
68
|
-
file.write(selection)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def self.current_deck
|
|
73
|
-
if File.exist?(DECK_FILE)
|
|
74
|
-
current_deck_id = File.read(DECK_FILE)
|
|
75
|
-
return Aro::Deck.find_by(id: current_deck_id)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def self.card_strip(card)
|
|
80
|
-
card.gsub(/[+-]/, "").strip
|
|
81
|
-
end
|
|
82
|
-
|
|
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"
|
|
107
|
-
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n\n"
|
|
108
|
-
h_text += "#{name.upcase.center(Aro::Deck::DISPLAY_WIDTH)}\n\n"
|
|
109
|
-
h_logs.each_with_index{|l, i|
|
|
110
|
-
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
111
|
-
h_text += l.created_at.strftime(Aro::Deck::DATE_FORMAT).center(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"
|
|
113
|
-
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n\n"
|
|
114
|
-
h_text += get_display_for_cards(
|
|
115
|
-
Base64::decode64(l.card_data).split(Aro::Deck::CARD_DELIM)
|
|
116
|
-
)
|
|
117
|
-
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
118
|
-
|
|
119
|
-
drawn_cards = Base64::decode64(l.drawn_data).split(Aro::Deck::CARD_DELIM)
|
|
120
|
-
|
|
121
|
-
if !drawn_cards.nil? && drawn_cards.any?
|
|
122
|
-
h_text += I18n.t("cli.messages.history_drawn").center(Aro::Deck::DISPLAY_WIDTH) + "\n"
|
|
123
|
-
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n\n"
|
|
124
|
-
h_text += get_display_for_cards(
|
|
125
|
-
drawn_cards
|
|
126
|
-
)
|
|
127
|
-
h_text += "\n"
|
|
128
|
-
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
3.times do
|
|
132
|
-
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
133
|
-
end
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if count_n == Aro::Log::DEFAULT_COUNT
|
|
137
|
-
Aro::P.say(h_text)
|
|
138
|
-
else
|
|
139
|
-
Aro::P.less(h_text)
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def get_display_for_cards(input = []) # todo:, print_nums: false)
|
|
144
|
-
result = ""
|
|
145
|
-
input.each_with_index{|c, i|
|
|
146
|
-
if i == I18n.t("cards.index").count - 1
|
|
147
|
-
result += c.ljust(Aro::Deck::DISPLAY_WIDTH)
|
|
148
|
-
else
|
|
149
|
-
result += c.ljust(Aro::Deck::DRAW_COUNT) + ((i + 1) % Aro::Deck::DRAW_COUNT == 0 ? "\n" : "")
|
|
150
|
-
end
|
|
151
|
-
}
|
|
152
|
-
result += "\n"
|
|
153
|
-
result
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def explore
|
|
157
|
-
# allows user to browse each card in the current deck.
|
|
158
|
-
answer = Aro::P.p.select(
|
|
159
|
-
I18n.t("cli.messages.choose_card"),
|
|
160
|
-
# formatted for tty-prompt gem
|
|
161
|
-
cards.split(Aro::Deck::CARD_DELIM).map{|c| [I18n.t("cards.#{Aro::Deck.card_strip(c)}.name"), c]}.to_h,
|
|
162
|
-
per_page: 7,
|
|
163
|
-
cycle: true,
|
|
164
|
-
default: 1
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
Aro::P.say(I18n.t("cards.#{Aro::Deck.card_strip(answer)}"))
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def shuffle
|
|
171
|
-
# shuffles the current deck and generates a log record.
|
|
172
|
-
update(cards: cards.split(Aro::Deck::CARD_DELIM).shuffle.join(Aro::Deck::CARD_DELIM))
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def reset
|
|
176
|
-
# completely reset the deck. replace all drawn and reset order.
|
|
177
|
-
# all orientations will be set to upright.
|
|
178
|
-
update(cards: Aro::Deck.fresh_cards, drawn: "")
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def replace
|
|
182
|
-
# replaces all drawn cards FIFO and puts them on the bottom of
|
|
183
|
-
# the deck. this will preserve all card orientations.
|
|
184
|
-
cards_arr = cards.split(Aro::Deck::CARD_DELIM) || []
|
|
185
|
-
drawn_arr = drawn&.split(Aro::Deck::CARD_DELIM) || []
|
|
186
|
-
|
|
187
|
-
# append each drawn card to cards
|
|
188
|
-
drawn_arr.each{|dc| cards_arr << dc }
|
|
189
|
-
|
|
190
|
-
# clear drawn
|
|
191
|
-
update(drawn: "", cards: cards_arr.join(Aro::Deck::CARD_DELIM))
|
|
192
|
-
end
|
|
193
|
-
|
|
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(Aro::Mancy::N)}
|
|
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
|
|
238
|
-
dev_tarot = nil
|
|
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
|
-
sleeps = 0
|
|
248
|
-
sleeps_max = z_max
|
|
249
|
-
|
|
250
|
-
# find a card that is not already drawn
|
|
251
|
-
while sleeps <= sleeps_max && dev_tarot.nil? do
|
|
252
|
-
# use fallback randomness if /dev/tarot unavailable
|
|
253
|
-
if !is_dt_dimension || !File.exist?(Aro::Deck::DEV_TAROT_FILE)
|
|
254
|
-
dev_tarot = summon_ruby_facot(cards_arr).split("")
|
|
255
|
-
else
|
|
256
|
-
# preferred randomness
|
|
257
|
-
read_value = Aro::Deck.read_dev_tarot&.strip&.split("")
|
|
258
|
-
if read_value.count >= Aro::Mancy::N - 1
|
|
259
|
-
dev_tarot = read_value
|
|
260
|
-
end
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
unless dev_tarot.nil?
|
|
264
|
-
abs_dev_tarot = dev_tarot[Aro::Mancy::S] + Aro::NUMERALS.key(
|
|
265
|
-
dev_tarot.join("")[Aro::Mancy::OS..].to_i
|
|
266
|
-
).to_s
|
|
267
|
-
if abs_cards_arr.include?(abs_dev_tarot)
|
|
268
|
-
# dev_tarot is valid
|
|
269
|
-
dev_tarot = dev_tarot[Aro::Mancy::O] + abs_dev_tarot
|
|
270
|
-
else
|
|
271
|
-
dev_tarot = nil
|
|
272
|
-
end
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
if dev_tarot.nil?
|
|
276
|
-
# dev_tarot is invalid
|
|
277
|
-
sleeps += 1
|
|
278
|
-
sleep(z.to_i)
|
|
279
|
-
end
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
# remove from cards
|
|
283
|
-
cards_arr.delete(cards_arr.select{|c| c.include?(abs_dev_tarot)}.first)
|
|
284
|
-
|
|
285
|
-
# insert dev_tarot to drawn
|
|
286
|
-
drawn_arr << dev_tarot
|
|
287
|
-
|
|
288
|
-
# update database
|
|
289
|
-
update(
|
|
290
|
-
cards: cards_arr.join(Aro::Deck::CARD_DELIM),
|
|
291
|
-
drawn: drawn_arr.join(Aro::Deck::CARD_DELIM)
|
|
292
|
-
)
|
|
293
|
-
end
|
|
294
|
-
end
|