Class: RuneRb::Game::Map::Regional

Inherits:
Object
  • Object
show all
Includes:
System::Log
Defined in:
app/game/map/regional.rb

Overview

An object holding the top left X and Y coordinates of a region

Since:

  • 0.9.3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from System::Log

#class_name, #err, #err!, #log, #log!, #symbolize_file

Constructor Details

#initialize(regional_x, regional_y) ⇒ Regional

Called when a new Regional is created

Parameters:

  • regional_x (Integer)

    the regional_x coordinate

  • regional_y (Integer)

    the regional_y coordinate

Since:

  • 0.9.3


11
12
13
# File 'app/game/map/regional.rb', line 11

def initialize(regional_x, regional_y)
  @coordinates = { x: regional_x, y: regional_y }
end

Instance Attribute Details

#coordinatesObject (readonly)

The x and y coordinates for the regional. (comparable to Position#top_left_region_x, or Position#top_left_region_y)

Since:

  • 0.9.3


6
7
8
# File 'app/game/map/regional.rb', line 6

def coordinates
  @coordinates
end

Class Method Details

.from_position(other) ⇒ Regional

Returns regional Position for the given Position.

Parameters:

  • other (Position)

    the Position to get the regional for

Returns:

  • (Regional)

    regional Position for the given Position

Since:

  • 0.9.3


58
59
60
# File 'app/game/map/regional.rb', line 58

def from_position(other)
  Regional.new(other.central_region_x, other.central_region_y)
end

Instance Method Details

#[](coord) ⇒ Object

Shorthand coordinate retrieval.

Parameters:

  • coord (Symbol)

    the coordinate to retrieve.

Since:

  • 0.9.3


27
28
29
# File 'app/game/map/regional.rb', line 27

def [](coord)
  @coordinates[coord]
end

#[]=(coord, value) ⇒ Object

Shorthand coordinate assignment

Parameters:

  • coord (Symbol)

    the coordinate to assign.

  • value (Integer)

    the value to assign the coordinate to.

Since:

  • 0.9.3


34
35
36
# File 'app/game/map/regional.rb', line 34

def []=(coord, value)
  @coordinates[coord] = value
end

#absolute_xObject

The absolute X coordinate of this Region (comparable to Position#)

Since:

  • 0.9.3


16
17
18
# File 'app/game/map/regional.rb', line 16

def absolute_x
  RuneRb::Game::Map::REGION_TILE_LENGTH * (@coordinates[:x] + 6)
end

#absolute_yObject

The absolute Y coordinate of this Region (comparable to Position#)

Since:

  • 0.9.3


21
22
23
# File 'app/game/map/regional.rb', line 21

def absolute_y
  RuneRb::Game::Map::REGION_TILE_LENGTH * (@coordinates[:y] + 6)
end

#eql?(other) ⇒ Boolean

Checks if the Regional holds the same value as another

Returns:

  • (Boolean)

Since:

  • 0.9.3


39
40
41
42
43
# File 'app/game/map/regional.rb', line 39

def eql?(other)
  false unless other.is_a? Regional
  log "OtherX: #{other[:x]}, OtherY: #{other[:y]}", "ContextX: #{@coordinates[:x]}, ContextY: #{@coordinates[:y]}"
  @coordinates[:x] == other[:x] && @coordinates[:y] == other[:y]
end

#includes?(position) ⇒ Boolean

Checks if the Regional would include the given Position

Parameters:

Returns:

  • (Boolean)

Since:

  • 0.9.3


47
48
49
# File 'app/game/map/regional.rb', line 47

def includes?(position)
  Regional.from_position(position).eql?(self)
end

#inspectObject

Since:

  • 0.9.3


51
52
53
# File 'app/game/map/regional.rb', line 51

def inspect
  "CENTRAL: [CentralX:#{@coordinates[:x]}, CentralY:#{@coordinates[:y]}] || ABSOLUTE: [AbsoluteX:#{absolute_x}, AbsoluteY:#{absolute_y}]"
end