Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Subclassing root console #8

Open
ghost opened this issue Jun 2, 2014 · 0 comments
Open

Suggestion: Subclassing root console #8

ghost opened this issue Jun 2, 2014 · 0 comments

Comments

@ghost
Copy link

ghost commented Jun 2, 2014

Not sure if you're still actively developing, but if you are, then you might consider sub-classing Console and get the root_console as a separate class. It'll allow you to get rid of having that third parameter in the constructor while still being able to pass rootconsoles everywhere you pass regular consoles. It seems more rubyesque to do it that way.

Here's an example from my port:

module Rogue
  class RootConsole < Console
    def initialze(width, height)
      if width < 0
        fail ArgumentError, "width must be non-negative, was #{width}"
      elsif height < 0
        fail ArgumentError, "width must be non-negative, was #{width}"
      end

      @width = width
      @height = height
      @clear_cell = Console.clear_cell
      @out_of_bounds_cell = Console.out_of_bounds_cell
      @ptr = nil

      ObjectSpace.define_finalizer(self, self.class.finalize(@ptr))
    end

    def self.instance
      @instance ||= create_instance
    end

    def self.create_instance
      unless Rogue::System.initialized?
        error_message = "Rogue::System.initialize has not been called yet."
        fail error_message 
      end

      RootConsole.new(System.SCREEN_WIDTH, System.SCREEN_HEIGHT)
    end
    private_class_method :create_instance
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants