Class: RgssDb::App

Inherits:
Object
  • Object
show all
Includes:
Strings
Defined in:
lib/rgss_db/app.rb

Overview

Application class

Instance Method Summary collapse

Constructor Details

#initialize(data_path, options) ⇒ App

Creates a new app instance

Parameters:

  • data_path (String)

    RPG Maker database folder

  • options (Hash<Symbol, Object>)

    App options hash



92
93
94
95
96
97
98
99
100
# File 'lib/rgss_db/app.rb', line 92

def initialize(data_path, options)
  @options = process_options(options)
  @data_manager = DataManager.new(data_path)
  @cli = AppCli.new(
    data_folder: @data_manager.path,
    rgss_version: @data_manager.rgss_version,
    app_version: RgssDb::VERSION
  )
end

Instance Method Details

#startObject

Starts the app



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/rgss_db/app.rb', line 105

def start
  # Checks for debug usage to start the module or not
  unless Debug.disabled?
    debug_path = File.expand_path(opt_working_dir, @data_manager.path)
    Debug.start(debug_path)
    Debug.update_extra_info(@data_manager.path, @data_manager.rgss_version)
    Debug.write_debug_header
  end

  # Start application logic
  begin
    if opt_action
      # An action was given, avoid main menu loop
      Debug.log_info("bypassing app menu")

      # Logs current options
      Debug.log_info("options: #{@options}")

      # Creates the data files instances
      data_files = []
      case opt_action
      when APP_ACTION_EXPORT
        data_files = @data_manager.load_database_files

        # Checks if user selected specific file entries
        unless opt_file_entries.empty?
          data_files = data_files.keep_if do |data_file|
            opt_file_entries.any? { |entry| data_file.file?(entry) }
          end
        end
      when APP_ACTION_EXPORT_CUSTOM
        data_files = @data_manager.load_database_files.keep_if(&:customizable?)

        # Checks if user selected specific file entries
        unless opt_file_entries.empty?
          data_files = data_files.keep_if do |data_file|
            opt_file_entries.any? { |entry| data_file.file?(entry) }
          end
        end

        # Applies any possible object IDs list for each file entry
        data_files.each do |data_file|
          data_file.object_ids_update(*opt_file_object_ids(data_file.file))
        end
      when APP_ACTION_IMPORT
        data_files = @data_manager.load_extracted_files(opt_working_dir)

        # Checks if user selected specific file entries
        unless opt_file_entries.empty?
          data_files = data_files.keep_if do |data_file|
            opt_file_entries.any? { |entry| data_file.file?(entry) }
          end
        end
      when APP_ACTION_IMPORT_CUSTOM
        data_files = @data_manager.load_extracted_files_custom(opt_working_dir).keep_if(&:mergeable?)

        # Checks if user selected specific file entries
        unless opt_file_entries.empty?
          data_files = data_files.keep_if do |data_file|
            opt_file_entries.any? { |entry| data_file.file?(entry) }
          end
        end
      end

      # Perform the action for each data file created
      data_files.each { |data_file| do_action(opt_action, data_file) }
    else
      # No action given, run the app main menu loop
      Debug.log_info("running app menu")
      menu_main
    end
  rescue Error => e
    # Application error
    Debug.log_exception(e, @options)
    @cli.draw_empty_line
    @cli.draw_error(e.message)
    @cli.draw_empty_line
    @cli.prompt_pause
    retry
  rescue StandardError => e
    # Unknown error
    Debug.log_exception(e, @options)
    raise e
  end
end