Class: Core::Models::Campaigns::TokenPosition

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/core/models/campaigns/token_position.rb

Overview

This is the instanciation of a token in one of the map of the campaign

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mapCore::Models::Campaigns::Map

Returns the map where this token is instanciated.

Returns:



23
# File 'lib/core/models/campaigns/token_position.rb', line 23

embedded_in :map, class_name: 'Core::Models::Campaigns::Map', inverse_of: :positions

#tokenCore::Models::Campaigns::Token

Returns the source of the token, used to determine its appearance.

Returns:



27
# File 'lib/core/models/campaigns/token_position.rb', line 27

belongs_to :token, class_name: 'Core::Models::Campaigns::Token', inverse_of: :positions

#xInteger

Returns the number of cells from the left before this token.

Returns:

  • (Integer)

    the number of cells from the left before this token



16
# File 'lib/core/models/campaigns/token_position.rb', line 16

field :x, type: Integer, default: 0

#yInteger

Returns the number of cells from the top before this token.

Returns:

  • (Integer)

    the number of cells from the top before this token



19
# File 'lib/core/models/campaigns/token_position.rb', line 19

field :y, type: Integer, default: 0

Instance Method Details

#coordinates_boundsObject

Validates that the coordinates of the token position are in the map bounds.



32
33
34
35
# File 'lib/core/models/campaigns/token_position.rb', line 32

def coordinates_bounds
  errors.add(:x, 'bounds') if map.nil? or x < 0 or x >= map.width
  errors.add(:y, 'bounds') if map.nil? or y < 0 or y >= map.height
end