Class: Gameui::Marker

Inherits:
Object
  • Object
show all
Includes:
Ish::Utils, Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/gameui/marker.rb

Constant Summary collapse

ITEM_TYPE_LOCATION =

@TODO: this used to be gameui-location . How is this different from gameui-map ?

'::Gameui::Map'
ITEM_TYPE_MAP =
'gameui-map'
ITEM_TYPE_OBJ =
'gameui-obj'
ITEM_TYPES =
[ ITEM_TYPE_LOCATION, ITEM_TYPE_MAP, ITEM_TYPE_OBJ ]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ish::Utils

#export

Class Method Details

.activeObject



52
53
54
# File 'lib/gameui/marker.rb', line 52

def self.active
  where( is_active: true )
end

.permitted_to(profile) ⇒ Object

Active AND [ mine, shared, or public ]



45
46
47
48
49
# File 'lib/gameui/marker.rb', line 45

def self.permitted_to profile
  active.any_of( {is_public: true},
    {:shared_profile_ids => profile.id},
    {creator_profile_id: profile.id} )
end

.publicObject



41
42
43
# File 'lib/gameui/marker.rb', line 41

def self.public
  where( is_public: true )
end

Instance Method Details

#collect(export_object) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gameui/marker.rb', line 114

def collect export_object
  if image
    export_object[:image_assets][image.id.to_s] = image.id.to_s
  end
  if title_image
    export_object[:image_assets][title_image.id.to_s] = title_image.id.to_s
  end
  if !export_object[:maps][destination.id.to_s]
    destination.collect export_object
  end
end

#compute_w_hObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gameui/marker.rb', line 77

def compute_w_h
  if !image # @TODO: think about this
    self.h = self.w = 0
    return
  end
  begin
    geo = Paperclip::Geometry.from_file(Paperclip.io_adapters.for(image.image))
    self.w = geo.width
    self.h = geo.height
  rescue Paperclip::Errors::NotIdentifiedByImageMagickError => e
    puts! e, 'Could not #compute_w_h'
    # @TODO: do something with this
  end
end

#export_fieldsObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/gameui/marker.rb', line 97

def export_fields
  %w|
    centerOffsetX centerOffsetY creator_profile_id
    deleted_at description destination_id
    h
    is_active is_public item_type
    map_id
    name
    ordering
    url
    version
    w
    x
    y
  |
end

#is_3dObject



27
28
29
# File 'lib/gameui/marker.rb', line 27

def is_3d
  !!asset3d
end

#xObject

@TODO: abstract this into a module



34
# File 'lib/gameui/marker.rb', line 34

field :x, :type => Float, default: 0