rgss_db 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/COPYING.md +674 -0
  4. data/README.md +347 -0
  5. data/bin/rgss-db +4 -0
  6. data/bin/rgssdb +4 -0
  7. data/lib/rgss_db/app.rb +928 -0
  8. data/lib/rgss_db/controller/data_manager.rb +557 -0
  9. data/lib/rgss_db/model/data_file.rb +516 -0
  10. data/lib/rgss_db/model/data_file_factory.rb +94 -0
  11. data/lib/rgss_db/model/debug.rb +199 -0
  12. data/lib/rgss_db/model/errors.rb +17 -0
  13. data/lib/rgss_db/model/mixins/jsonable.rb +35 -0
  14. data/lib/rgss_db/model/mixins/jsonable_constructor.rb +40 -0
  15. data/lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb +72 -0
  16. data/lib/rgss_db/model/rpg_maker_data/vx/rgss/rect.rb +70 -0
  17. data/lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb +99 -0
  18. data/lib/rgss_db/model/rpg_maker_data/vx/rgss/tone.rb +72 -0
  19. data/lib/rgss_db/model/rpg_maker_data/vx/rgss.rb +11 -0
  20. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/actor.rb +44 -0
  21. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/animation.rb +31 -0
  22. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/animation_frame.rb +20 -0
  23. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/animation_timing.rb +23 -0
  24. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/area.rb +26 -0
  25. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/armor.rb +31 -0
  26. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/audio_file.rb +23 -0
  27. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/base_item.rb +25 -0
  28. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/bgm.rb +36 -0
  29. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/bgs.rb +36 -0
  30. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/class.rb +31 -0
  31. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/class_learning.rb +20 -0
  32. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/common_event.rb +25 -0
  33. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/enemy.rb +44 -0
  34. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/enemy_action.rb +29 -0
  35. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/enemy_drop_item.rb +23 -0
  36. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/event.rb +36 -0
  37. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/event_command.rb +19 -0
  38. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/event_page.rb +32 -0
  39. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/event_page_condition.rb +34 -0
  40. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/event_page_graphic.rb +25 -0
  41. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/item.rb +27 -0
  42. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/map.rb +47 -0
  43. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/map_info.rb +26 -0
  44. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/me.rb +27 -0
  45. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/move_command.rb +18 -0
  46. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/move_route.rb +20 -0
  47. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/se.rb +21 -0
  48. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/skill.rb +22 -0
  49. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/state.rb +47 -0
  50. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/system.rb +43 -0
  51. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/system_terms.rb +53 -0
  52. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/system_test_battler.rb +25 -0
  53. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/system_vehicle.rb +24 -0
  54. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/troop.rb +24 -0
  55. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/troop_member.rb +23 -0
  56. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/troop_page.rb +21 -0
  57. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/troop_page_condition.rb +33 -0
  58. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/usable_item.rb +87 -0
  59. data/lib/rgss_db/model/rpg_maker_data/vx/rpg/weapon.rb +31 -0
  60. data/lib/rgss_db/model/rpg_maker_data/vx/rpg.rb +59 -0
  61. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rgss/color.rb +72 -0
  62. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rgss/rect.rb +70 -0
  63. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rgss/table.rb +99 -0
  64. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rgss/tone.rb +72 -0
  65. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rgss.rb +11 -0
  66. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/actor.rb +27 -0
  67. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/animation.rb +31 -0
  68. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/animation_frame.rb +23 -0
  69. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/animation_timing.rb +26 -0
  70. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/armor.rb +20 -0
  71. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/audio_file.rb +23 -0
  72. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/base_item.rb +31 -0
  73. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/base_item_feature.rb +29 -0
  74. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/bgm.rb +43 -0
  75. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/bgs.rb +43 -0
  76. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/class.rb +37 -0
  77. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/class_learning.rb +24 -0
  78. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/common_event.rb +33 -0
  79. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/enemy.rb +27 -0
  80. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/enemy_action.rb +26 -0
  81. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/enemy_drop_item.rb +24 -0
  82. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/equip_item.rb +19 -0
  83. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/event.rb +36 -0
  84. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/event_command.rb +19 -0
  85. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/event_page.rb +35 -0
  86. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/event_page_condition.rb +40 -0
  87. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/event_page_graphic.rb +31 -0
  88. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/item.rb +25 -0
  89. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/map.rb +58 -0
  90. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/map_encounter.rb +23 -0
  91. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/map_info.rb +26 -0
  92. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/me.rb +27 -0
  93. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/move_command.rb +17 -0
  94. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/move_route.rb +19 -0
  95. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/se.rb +21 -0
  96. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/skill.rb +25 -0
  97. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/state.rb +34 -0
  98. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/system.rb +62 -0
  99. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/system_terms.rb +25 -0
  100. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/system_test_battler.rb +24 -0
  101. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/system_vehicle.rb +27 -0
  102. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/tileset.rb +26 -0
  103. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/troop.rb +24 -0
  104. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/troop_member.rb +25 -0
  105. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/troop_page.rb +24 -0
  106. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/troop_page_condition.rb +39 -0
  107. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/usable_item.rb +84 -0
  108. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/usable_item_damage.rb +56 -0
  109. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/usable_item_effect.rb +25 -0
  110. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg/weapon.rb +25 -0
  111. data/lib/rgss_db/model/rpg_maker_data/vx_ace/rpg.rb +66 -0
  112. data/lib/rgss_db/model/rpg_maker_data/xp/rgss/color.rb +72 -0
  113. data/lib/rgss_db/model/rpg_maker_data/xp/rgss/rect.rb +70 -0
  114. data/lib/rgss_db/model/rpg_maker_data/xp/rgss/table.rb +99 -0
  115. data/lib/rgss_db/model/rpg_maker_data/xp/rgss/tone.rb +72 -0
  116. data/lib/rgss_db/model/rpg_maker_data/xp/rgss.rb +11 -0
  117. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/actor.rb +44 -0
  118. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/animation.rb +28 -0
  119. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/animation_frame.rb +20 -0
  120. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/animation_timing.rb +24 -0
  121. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/armor.rb +37 -0
  122. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/audio_file.rb +23 -0
  123. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/class.rb +28 -0
  124. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/class_learning.rb +20 -0
  125. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/common_event.rb +25 -0
  126. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/enemy.rb +47 -0
  127. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/enemy_action.rb +28 -0
  128. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/event.rb +36 -0
  129. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/event_command.rb +19 -0
  130. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/event_page.rb +32 -0
  131. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/event_page_condition.rb +30 -0
  132. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/event_page_graphic.rb +27 -0
  133. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/item.rb +48 -0
  134. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/map.rb +39 -0
  135. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/map_info.rb +26 -0
  136. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/move_command.rb +18 -0
  137. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/move_route.rb +19 -0
  138. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/skill.rb +47 -0
  139. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/state.rb +51 -0
  140. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/system.rb +56 -0
  141. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/system_test_battler.rb +25 -0
  142. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/system_words.rb +39 -0
  143. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/tileset.rb +39 -0
  144. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/troop.rb +24 -0
  145. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/troop_member.rb +23 -0
  146. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/troop_page.rb +21 -0
  147. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/troop_page_condition.rb +32 -0
  148. data/lib/rgss_db/model/rpg_maker_data/xp/rpg/weapon.rb +38 -0
  149. data/lib/rgss_db/model/rpg_maker_data/xp/rpg.rb +52 -0
  150. data/lib/rgss_db/model/strings.rb +607 -0
  151. data/lib/rgss_db/model/utilities.rb +90 -0
  152. data/lib/rgss_db/version.rb +7 -0
  153. data/lib/rgss_db/view/app_cli.rb +449 -0
  154. data/lib/rgss_db.rb +41 -0
  155. data/sig/rgss_db.rbs +5221 -0
  156. metadata +496 -0
@@ -0,0 +1,449 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "colorize"
4
+ require "tty-screen"
5
+ require "tty-box"
6
+ require "tty-table"
7
+ require "tty-prompt"
8
+ require "tty-progressbar"
9
+ require "tty-spinner"
10
+ require_relative "../model/strings"
11
+
12
+ module RgssDb
13
+ # Value that determines the number of options per page on the select prompt
14
+ # @return [Integer]
15
+ APP_CLI_SELECT_PER_PAGE = 7
16
+
17
+ # Value that determines the number of options per page on the multi select prompt
18
+ # @return [Integer]
19
+ APP_CLI_MULTI_SELECT_PER_PAGE = 7
20
+
21
+ # Value that determines the enumator character for the multi select prompt
22
+ # @return [String]
23
+ APP_CLI_MULTI_SELECT_ENUM_CHAR = "."
24
+
25
+ #
26
+ # Application CLI
27
+ #
28
+ class AppCli
29
+ include Strings
30
+
31
+ # Application version shown on the CLI
32
+ # @return [String]
33
+ attr_accessor :app_version
34
+
35
+ # RPG Maker version shown on the CLI
36
+ # @return [Symbol]
37
+ attr_accessor :rgss_version
38
+
39
+ # Data folder path shown on the CLI
40
+ # @return [Symbol]
41
+ attr_accessor :data_folder
42
+
43
+ #
44
+ # Creates a new app cli instance
45
+ #
46
+ # @param data_folder [String] RPG Maker database path
47
+ # @param app_version [String] Application version
48
+ # @param rgss_version [Symbol] RGSS version
49
+ #
50
+ def initialize(data_folder: nil, app_version: nil, rgss_version: nil)
51
+ @app_version = app_version
52
+ @rgss_version = rgss_version
53
+ @data_folder = data_folder
54
+ @prompt = TTY::Prompt.new
55
+ end
56
+
57
+ #
58
+ # Resets the console screen position with a escape sequence
59
+ #
60
+ def reset_screen
61
+ puts "\e[H\e[2J"
62
+ end
63
+
64
+ #
65
+ # Draws all strings on the standard output
66
+ #
67
+ # @param strings [Array<String>] Strings
68
+ # @param color [Symbol] Color symbol
69
+ #
70
+ def draw(*strings, color: nil)
71
+ strings.each do |str|
72
+ puts color ? str.to_s.colorize(color) : str.to_s
73
+ end
74
+ end
75
+
76
+ #
77
+ # Draws an empty line on the standard output
78
+ #
79
+ def draw_empty_line
80
+ draw("")
81
+ end
82
+
83
+ #
84
+ # Draws ``string`` on the standard output as info
85
+ #
86
+ # @param string [String] String
87
+ #
88
+ def draw_info(string)
89
+ draw(string, color: :blue)
90
+ end
91
+
92
+ #
93
+ # Draws ``string`` on the standard output as a warning
94
+ #
95
+ # @param string [String] String
96
+ #
97
+ def draw_warning(string)
98
+ draw(string, color: :yellow)
99
+ end
100
+
101
+ #
102
+ # Draws ``string`` on the standard output as an error
103
+ #
104
+ # @param string [String] String
105
+ #
106
+ def draw_error(string)
107
+ draw(string, color: :red)
108
+ end
109
+
110
+ #
111
+ # Draws the user's navigation in the standard output
112
+ #
113
+ # Nothing is drawn if the ``breadcrumbs`` array is empty
114
+ #
115
+ # @param breadcrumbs [Array<String>] List of breadcrumbs
116
+ #
117
+ def draw_navigation(*breadcrumbs)
118
+ draw(breadcrumbs.join(" -> "), color: :blue) unless breadcrumbs.empty?
119
+ end
120
+
121
+ #
122
+ # Draws a frame with the given contents on the standard output
123
+ #
124
+ # Nothing is drawn if the ``contents`` array is empty
125
+ #
126
+ # @param contents [Array<String>] Frame contents
127
+ #
128
+ def draw_frame(*contents)
129
+ return if contents.empty?
130
+
131
+ box = TTY::Box.frame(*contents)
132
+ draw(box)
133
+ end
134
+
135
+ #
136
+ # Draws an information frame with the given contents on the standard output
137
+ #
138
+ # Nothing is drawn if the ``contents`` array is empty
139
+ #
140
+ # @param contents [Array<String>] Frame contents
141
+ #
142
+ def draw_info_frame(*contents)
143
+ return if contents.empty?
144
+
145
+ box = TTY::Box.frame(
146
+ *contents,
147
+ title: { top_left: StrOthers::INFO_FRAME_LABEL }
148
+ )
149
+ draw(box)
150
+ end
151
+
152
+ #
153
+ # Draws a warning frame with the given contents on the standard output
154
+ #
155
+ # Nothing is drawn if the ``contents`` array is empty
156
+ #
157
+ # @param contents [Array<String>] Frame contents
158
+ #
159
+ def draw_warning_frame(*contents)
160
+ return if contents.empty?
161
+
162
+ box = TTY::Box.frame(
163
+ *contents,
164
+ title: { top_left: StrOthers::WARN_FRAME_LABEL }
165
+ )
166
+ draw(box, color: :yellow)
167
+ end
168
+
169
+ #
170
+ # Draws an error frame with the given contents on the standard output
171
+ #
172
+ # Nothing is drawn if the ``contents`` array is empty
173
+ #
174
+ # @param contents [Array<String>] Frame contents
175
+ #
176
+ def draw_error_frame(*contents)
177
+ return if contents.empty?
178
+
179
+ box = TTY::Box.frame(
180
+ *contents,
181
+ title: { top_left: StrOthers::ERRO_FRAME_LABEL }
182
+ )
183
+ draw(box, color: :red)
184
+ end
185
+
186
+ #
187
+ # Draws a table on the standard output
188
+ #
189
+ # The number of ``columns`` and the size of each row in ``rows`` must have the same length
190
+ #
191
+ # Columns: [Column1, Column2]
192
+ # Rows: [["a", "b"], ["c", "d"]]
193
+ #
194
+ # @param columns [Array<String>] Columns
195
+ # @param rows [Array<String>] List of rows
196
+ # @param render_type [Symbol] Table render type
197
+ #
198
+ def draw_table(columns, *rows, render_type: :unicode)
199
+ table = TTY::Table.new(
200
+ columns,
201
+ rows
202
+ )
203
+ draw(table.render(render_type))
204
+ end
205
+
206
+ #
207
+ # Draws a success operation to the terminal
208
+ #
209
+ # @param success_message [String] Success message
210
+ #
211
+ def draw_success_operation(success_message = nil)
212
+ draw_empty_line
213
+ draw(success_message || StrPrompts::SUCCESS_TEXT, color: :green)
214
+ draw_empty_line
215
+ end
216
+
217
+ #
218
+ # Draws a cancel operation to the terminal
219
+ #
220
+ # @param cancel_message [String] Cancel message
221
+ #
222
+ def draw_cancel_operation(cancel_message = nil)
223
+ draw_empty_line
224
+ draw(cancel_message || StrPrompts::CANCEL_TEXT, color: :red)
225
+ draw_empty_line
226
+ end
227
+
228
+ #
229
+ # Draws the app header on the standard output
230
+ #
231
+ def draw_app_header
232
+ # App title
233
+ draw <<~EOF
234
+ ██████ ██████ ███████ ███████ ██████ █████ ████████ █████ ██████ █████ ███████ ███████
235
+ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
236
+ ██████ ██ ███ ███████ ███████ ██ ██ ███████ ██ ███████ ██████ ███████ ███████ █████
237
+ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
238
+ ██ ██ ██████ ███████ ███████ ██████ ██ ██ ██ ██ ██ ██████ ██ ██ ███████ ███████
239
+ v#{@app_version}
240
+ EOF
241
+ .colorize(:green)
242
+ end
243
+
244
+ #
245
+ # Draws the app information on the standard output
246
+ #
247
+ def draw_app_info
248
+ # Data folder
249
+ draw(format(StrAppInfo::DATA_FOLDER, @data_folder), color: :green)
250
+ # Detected RGSS version
251
+ draw(format(StrAppInfo::RPG_VERSION, @rgss_version || StrAppInfo::VERSION_INVALID_LABEL), color: :green)
252
+
253
+ # Draw warning frame in case rpg maker version is unknown
254
+ return unless @rgss_version.nil?
255
+
256
+ draw_empty_line
257
+ draw_warning_frame(StrAppInfo::VERSION_INVALID_TEXT)
258
+ end
259
+
260
+ #
261
+ # Draws a menu header on the terminal
262
+ #
263
+ # This header is common for every application menu
264
+ #
265
+ # @param menu_contents [Array<String>] Menu information contents
266
+ # @param breadcrumbs [Array<String>] Breadcrumbs list
267
+ #
268
+ def draw_app_menu(*menu_contents, breadcrumbs: nil)
269
+ reset_screen
270
+ draw_app_header
271
+ draw_empty_line
272
+ draw_app_info
273
+ draw_empty_line
274
+
275
+ # Draw breadcrumbs on screen
276
+ unless breadcrumbs.nil?
277
+ draw_navigation(*breadcrumbs)
278
+ draw_empty_line
279
+ end
280
+
281
+ # Draw information panel on screen
282
+ return if menu_contents.empty?
283
+
284
+ draw_info_frame(*menu_contents)
285
+ draw_empty_line
286
+ end
287
+
288
+ #
289
+ # Draws a submenu header on the terminal
290
+ #
291
+ # This header is common for every application submenu
292
+ #
293
+ # @param menu_contents [Array<String>] Menu information contents
294
+ # @param breadcrumbs [Array<String>] Breadcrumbs list
295
+ #
296
+ def draw_app_submenu(*menu_contents, breadcrumbs: nil)
297
+ reset_screen
298
+
299
+ # Draw breadcrumbs on screen
300
+ unless breadcrumbs.nil?
301
+ draw_navigation(*breadcrumbs)
302
+ draw_empty_line
303
+ end
304
+
305
+ # Draw menu contents on screen
306
+ return if menu_contents.empty?
307
+
308
+ draw_info_frame(*menu_contents)
309
+ draw_empty_line
310
+ end
311
+
312
+ #
313
+ # Executes and draws a terminal pause to the standard output
314
+ #
315
+ # If ``timeout`` is given, the execution will be resumed after that time
316
+ #
317
+ # @param keys [Array<Symbol>] List of key symbols
318
+ # @param timeout [Integer] Time out in seconds
319
+ #
320
+ def prompt_pause(*keys, timeout: nil)
321
+ if keys.empty?
322
+ # No specific keys
323
+ if timeout
324
+ @prompt.keypress(
325
+ StrPrompts::PAUSE_ANY_KEYS_TIMEOUT.colorize(:green),
326
+ timeout: timeout
327
+ )
328
+ else
329
+ @prompt.keypress(
330
+ StrPrompts::PAUSE_ANY_KEYS.colorize(:green)
331
+ )
332
+ end
333
+ else
334
+ # Specific keys
335
+ key_names = keys.map { |key| key.to_s.upcase }.join(", ")
336
+ if timeout
337
+ @prompt.keypress(
338
+ format(StrPrompts::PAUSE_KEYS_TIMEOUT, key_names).colorize(:green),
339
+ keys: keys,
340
+ timeout: timeout
341
+ )
342
+ else
343
+ @prompt.keypress(
344
+ format(StrPrompts::PAUSE_KEYS, key_names).colorize(:green),
345
+ keys: keys
346
+ )
347
+ end
348
+ end
349
+ end
350
+
351
+ #
352
+ # Executes and draws an user confirmation on the standard output
353
+ #
354
+ # @param input_text [String] Menu text
355
+ # @param default [Boolean] Default option
356
+ #
357
+ # @return [Boolean]
358
+ #
359
+ def prompt_confirm?(input_text = nil, default: true)
360
+ @prompt.yes?(input_text || StrPrompts::CONFIRM_INPUT_TEXT, default: default)
361
+ end
362
+
363
+ #
364
+ # Executes and draws an user input on the standard output
365
+ #
366
+ # @param question [String] Question to ask
367
+ # @param default [String] Default option
368
+ # @param value [String] Pre-populated value
369
+ # @param required [Boolean] Force input
370
+ # @param convert [Symbol] Conversion symbol
371
+ # @param validate_text [String] Validation fail text
372
+ # @param validate [Proc] Validation callback
373
+ #
374
+ # @yieldparam [String]
375
+ #
376
+ # @return [String]
377
+ #
378
+ def prompt_ask(question, default: nil, value: nil, required: false, convert: nil, validate_text: nil, &validate)
379
+ @prompt.ask(
380
+ question,
381
+ default: default,
382
+ value: value,
383
+ required: required,
384
+ convert: convert || :string
385
+ ) do |ask|
386
+ ask.validate ->(input) { yield input }, validate_text || StrPrompts::ASK_VALIDATION_FAIL_TEXT if block_given?
387
+ end
388
+ end
389
+
390
+ #
391
+ # Executes and draws a menu selection on the standard output+
392
+ #
393
+ # If ``menu_cycle`` is true, the selection will cycle around if the top/bottom option is reached
394
+ #
395
+ # @param menu_options [Array] List of menu options
396
+ # @param default [Array] Default options
397
+ # @param input_text [String] Menu text
398
+ # @param menu_cycle [Boolean] Menu cycle status
399
+ #
400
+ # @return [String] Selected option
401
+ #
402
+ def prompt_select(*menu_options, default: nil, input_text: nil, menu_cycle: false)
403
+ @prompt.select(
404
+ input_text || StrPrompts::SELECT_INPUT_TEXT,
405
+ menu_options,
406
+ default: default,
407
+ cycle: menu_cycle,
408
+ per_page: APP_CLI_SELECT_PER_PAGE
409
+ )
410
+ end
411
+
412
+ #
413
+ # Executes and draws a menu selection on the standard output+
414
+ #
415
+ # If ``menu_cycle`` is true, the selection will cycle around if the top/bottom option is reached
416
+ #
417
+ # @param menu_options [Array] List of menu options
418
+ # @param default [Array] Default options
419
+ # @param input_text [String] Menu text
420
+ # @param menu_cycle [Boolean] Menu cycle status
421
+ #
422
+ # @return Selected options
423
+ #
424
+ def prompt_select_multi(*menu_options, default: nil, input_text: nil, menu_cycle: false)
425
+ @prompt.multi_select(
426
+ input_text || StrPrompts::SELECT_INPUT_TEXT,
427
+ menu_options,
428
+ default: default,
429
+ cycle: menu_cycle,
430
+ per_page: APP_CLI_MULTI_SELECT_PER_PAGE,
431
+ enum: APP_CLI_MULTI_SELECT_ENUM_CHAR
432
+ )
433
+ end
434
+
435
+ #
436
+ # Executes and draws a spinner with a routine on the standard output
437
+ #
438
+ # This method allows to execute a block while a spinner is drawn on the screen
439
+ #
440
+ # @param text [String] Spinner text
441
+ # @param block [Proc]
442
+ # @yieldparam spinner [TTY::Spinner]
443
+ #
444
+ def prompt_spinner(text, &block)
445
+ spinner = TTY::Spinner.new("[:spinner] #{text}", format: :dots)
446
+ spinner.run(StrPrompts::SPINNER_TASK_COMPLETED_TEXT) { yield spinner }
447
+ end
448
+ end
449
+ end
data/lib/rgss_db.rb ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "optimist"
5
+ require_relative "./rgss_db/app"
6
+
7
+ #
8
+ # Application module
9
+ #
10
+ module RgssDb
11
+ #
12
+ # Entry point module
13
+ #
14
+ module EntryPoint
15
+ include Strings::StrAppEntryPoint
16
+
17
+ # Process user options with optimist before running the app
18
+ opts = Optimist.options do
19
+ version format(CLI_VERSION, RgssDb::VERSION)
20
+ banner CLI_BANNER
21
+
22
+ opt APP_OPTION_BACK_UP, CLI_OPTION_BACK_UP, short: :none, default: APP_DEFAULT_BACK_UP
23
+ opt APP_OPTION_DEBUG_MODE, CLI_OPTION_DEBUG_MODE, type: Integer, short: :none, default: APP_DEFAULT_DEBUG_MODE
24
+ opt APP_OPTION_WORKING_DIR, CLI_OPTION_WORKING_DIR, type: String, default: APP_DEFAULT_WORKING_DIR
25
+ opt APP_OPTION_ACTION, CLI_OPTION_ACTION, type: String
26
+ opt APP_OPTION_FORMAT_TYPE, CLI_OPTION_FORMAT_TYPE, type: String, default: APP_DEFAULT_FORMAT_TYPE
27
+ opt APP_OPTION_FILE_ENTRIES, CLI_OPTION_FILE_ENTRIES, type: :strings
28
+ opt APP_OPTION_IDS, CLI_OPTION_IDS, type: :integers, multi: true
29
+ end
30
+
31
+ # Gets the data directory (should be the only valid positional argument)
32
+ path = ARGV.shift
33
+ # Create and starts the app
34
+ if path.nil? || path.empty?
35
+ puts CLI_INVALID_CALL_MSG
36
+ else
37
+ app = RgssDb::App.new(path, opts)
38
+ app.start
39
+ end
40
+ end
41
+ end