Sha256: c7438c515a4576e4272fb0c69ab7dc3bc7687861cc5122cf15bd10eab820b077

Contents?: true

Size: 1 KB

Versions: 28

Compression:

Stored size: 1 KB

Contents

class ProconBypassMan::Procon::ModeRegistry
  class Mode
    attr_accessor :name, :binaries, :source_binaries

    def initialize(name: , binaries: )
      self.name = name
      self.binaries = binaries
      self.source_binaries = binaries.dup
    end

    def next_binary
      binary = binaries.shift
      unless binary
        self.binaries = source_binaries.dup
        return binaries.shift
      end
      return binary
    end
  end

  PRESETS = {
    manual: [],
  }

  def self.install_plugin(klass)
    if plugins[klass.to_s.to_sym]
      raise "#{klass} mode is already registered"
    end
    plugins[klass.to_s.to_sym] = ->{ klass.binaries }
  end

  def self.load(name)
    b = PRESETS[name] || plugins[name]&.call || raise("#{name} is unknown mode")
    Mode.new(name: name, binaries: b.dup)
  end

  def self.reset!
    ProconBypassMan::ButtonsSettingConfiguration.instance.mode_plugins = {}
  end

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

  reset!
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.11 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.3.1 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.3 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.2 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.1 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.3.0 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.2.3 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.2.2 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.2.1 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.2.0 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.1.23 lib/procon_bypass_man/procon/mode_registry.rb
procon_bypass_man-0.1.22 lib/procon_bypass_man/procon/mode_registry.rb