Module: Mmi::Interactive::Modloader

Defined in:
lib/mmi/interactive/modloader.rb

Instance Method Summary collapse

Instance Method Details

#update_modloaderObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mmi/interactive/modloader.rb', line 9

def update_modloader
  choice = CLI::UI::Prompt.ask('What do you want to do?') do |handler|
    [
      (["Update current modloader #{self.processor.modloader['name']}", :update_current] unless self.processor.modloader.is_a?(Mmi::Modloader::None)),
      ['quit',                                                          :quit          ],
    ].each do |name, result|
      handler.option(name) do
        result
      end
    end
  end
  
  case choice
    when :update_current
      update_modloader_current
    when :quit
      # Pass.
    else
      raise 'Consider yourself lucky, you found a bug.'
  end
end

#update_modloader_currentObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
# File 'lib/mmi/interactive/modloader.rb', line 31

def update_modloader_current
  ml = self.processor.modloader
  
  case ml
    when Mmi::Modloader::None
      CLI::UI.puts('There is currently no modloader set, please choose one first.', color: CLI::UI::Color::RED)
    when Mmi::Modloader::Fabric
      loop do
        choice = CLI::UI::Prompt.ask('What do you want to update?') do |handler|
          [
            ['Installer version',   :version           ],
            ['Minecraft version',   :minecraft_version ],
            ['Download Minecraft?', :download_minecraft],
            ['Install directory',   :install_dir       ],
            ['Install type',        :install_type      ],
            ['quit',                :quit              ],
          ].each do |name, result|
            handler.option(name) do
              result
            end
          end
        end
        
        case choice
          when :version
            choice2 = CLI::UI::Prompt.ask('Choose a fabric installer version') do |handler|
              ml.available_versions.sort.reverse.each do |v|
                handler.option(v, &:itself)
              end
              
              handler.option('quit', &:to_sym)
            end
            
            case choice2
              when :quit
                # Pass.
              else
                ml.update_properties!({version: choice2})
            end
          when :minecraft_version
            choice2 =
              begin
                CLI::UI::Prompt.ask('Which Minecraft version do you need?')
              rescue Interrupt
                :quit
              end
            
            case choice2
              when :quit
                # Pass.
              else
                ml.update_properties!({minecraft_version: choice2})
            end
          when :download_minecraft
            choice2 =
              begin
                CLI::UI::Prompt.confirm('Download minecraft when installing the modloader? (Ctrl+C for no change)', default: ml.download_minecraft)
              rescue Interrupt
                :quit
              end
            
            case choice2
              when :quit
                # Pass.
              else
                ml.update_properties!({download_minecraft: choice2})
            end
          when :install_dir
            choice2 =
              begin
                CLI::UI::Prompt.ask('In which directory should the modloader be installed? ', is_file: true)
              rescue Interrupt
                :quit
              end
            
            case choice2
              when :quit
                # Pass.
              else
                ml.update_properties!({install_dir: choice2.strip.empty? ? nil : choice2})
            end
          when :install_type
            choice2 = CLI::UI::Prompt.ask('What type of installation do you want?') do |handler|
              ml.allowed_install_types.each do |type|
                handler.option(type, &:itself)
              end
              
              handler.option('quit', &:to_sym)
            end
            
            case choice2
              when :quit
                # Pass.
              else
                ml.update_properties!({install_type: choice2})
            end
          when :quit
            break
          else
            raise 'Consider yourself lucky, you found a bug.'
        end
      end
    else
      CLI::UI.puts("Modloader #{self.processor.modloader['name']} is not supported.", color: CLI::UI::Color::RED)
  end
end