Class: ProconBypassMan::Procon::MacroRegistry2

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/procon/macro_registry2.rb

Constant Summary collapse

PRESETS =
{
  null: [],
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMacroRegistry2

Returns a new instance of MacroRegistry2.



10
11
12
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 10

def initialize
  self.plugins = ProconBypassMan::Procon::MacroPluginMap.new
end

Instance Attribute Details

#pluginsObject

Returns the value of attribute plugins.



4
5
6
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 4

def plugins
  @plugins
end

Instance Method Details

#cleanup_remote_macros!Object



38
39
40
41
42
43
44
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 38

def cleanup_remote_macros!
  remote_keys = plugins.original_keys.select { |_, y| y == :remote }
  remote_keys.each do |remote_key|
    plugins.delete(remote_key)
  end
  plugins
end

#install_plugin(klass, steps: nil, macro_type: :normal) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 14

def install_plugin(klass, steps: nil, macro_type: :normal)
  if plugins.fetch([klass.to_s.to_sym, macro_type], nil)
    Kernel.warn "#{klass} macro is already registered"
    return
  end

  plugins.store(
    [klass.to_s.to_sym, macro_type], ->{
      ProconBypassMan::Procon::MacroBuilder.new(steps || klass.steps).build
    }
  )
end

#load(name, macro_type: :normal, force_neutral_buttons: [], &after_callback_block) ⇒ ProconBypassMan::Procon::Macro



28
29
30
31
32
33
34
35
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 28

def load(name, macro_type: :normal, force_neutral_buttons: [], &after_callback_block)
  if(steps = PRESETS[name] || plugins.fetch([name.to_s.to_sym, macro_type], nil)&.call)
    return ProconBypassMan::Procon::Macro.new(name: name, steps: steps.dup, force_neutral_buttons: force_neutral_buttons, &after_callback_block)
  else
    warn "installされていないマクロ(#{name})を使うことはできません"
    return self.load(:null)
  end
end