Sha256: 58dd49d8721c4d27e97d6d9aaeba710509708f41906f629cfe310d9fabbb6665

Contents?: true

Size: 1.53 KB

Versions: 14

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

class ProconBypassMan::Procon::MacroRegistry
  PRESETS = {
    null: [],
  }

  def self.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

  # @return [ProconBypassMan::Procon::Macro]
  def self.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

  def self.reset!
    ProconBypassMan::ButtonsSettingConfiguration.instance.macro_plugins = ProconBypassMan::Procon::MacroPluginMap.new
  end

  def self.plugins
    ProconBypassMan::ButtonsSettingConfiguration.instance.macro_plugins
  end

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

  reset!
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.11 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.3.1 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.3 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.2 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.1 lib/procon_bypass_man/procon/macro_registry.rb
procon_bypass_man-0.3.0 lib/procon_bypass_man/procon/macro_registry.rb