Module: Lich::Common::GUI::State

Defined in:
documented/common/gui/state.rb

Class Method Summary collapse

Class Method Details

.apply_theme_settings(theme_state) ⇒ void

This method returns an undefined value.

Applies the theme settings based on the provided state.

Examples:

Lich::Common::GUI::State.apply_theme_settings(true)

Parameters:

  • theme_state (Boolean)

    Indicates whether to prefer a dark theme.



59
60
61
# File 'documented/common/gui/state.rb', line 59

def self.apply_theme_settings(theme_state)
  Gtk::Settings.default.gtk_application_prefer_dark_theme = true if theme_state == true
end

.load_saved_entries(data_dir, autosort_state) ⇒ Array

Loads saved entries from a specified data directory.

Examples:

entries = Lich::Common::GUI::State.load_saved_entries("/path/to/data", true)

Parameters:

  • data_dir (String)

    The directory where the entry.dat file is located.

  • autosort_state (Boolean)

    Determines the sorting order of the entries.

Returns:

  • (Array)

    The sorted array of entries or an empty array if loading fails.

Raises:

  • (StandardError)

    If there is an issue reading the file.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'documented/common/gui/state.rb', line 13

def self.load_saved_entries(data_dir, autosort_state)
  if File.exist?(File.join(data_dir, "entry.dat"))
    File.open(File.join(data_dir, "entry.dat"), 'r') { |file|
      begin
        if autosort_state
          # Sort in list by instance name, account name, and then character name
          Marshal.load(file.read.unpack('m').first).sort do |a, b|
            [a[:game_name], a[:user_id], a[:char_name]] <=> [b[:game_name], b[:user_id], b[:char_name]]
          end
        else
          # Sort in list by account name, and then character name (old Lich 4)
          Marshal.load(file.read.unpack('m').first).sort do |a, b|
            [a[:user_id].downcase, a[:char_name]] <=> [b[:user_id].downcase, b[:char_name]]
          end
        end
      rescue
        Array.new
      end
    }
  else
    Lich.log "Info: No entry.dat file detected, probable new installation."
    Array.new
  end
end

.save_entries(data_dir, entry_data) ⇒ Boolean

Saves the given entry data to the specified data directory.

Examples:

success = Lich::Common::GUI::State.save_entries("/path/to/data", entries)

Parameters:

  • data_dir (String)

    The directory where the entry.dat file will be saved.

  • entry_data (Array)

    The data to be saved as entries.

Returns:

  • (Boolean)

    Returns true if the entries were saved successfully, false otherwise.

Raises:

  • (StandardError)

    If there is an issue writing to the file.



45
46
47
48
49
50
51
52
# File 'documented/common/gui/state.rb', line 45

def self.save_entries(data_dir, entry_data)
  File.open(File.join(data_dir, "entry.dat"), 'w') { |file|
    file.write([Marshal.dump(entry_data)].pack('m'))
  }
  true
rescue
  false
end