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



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

def self.active
  where( is_active: true )
end

.permitted_to(profile) ⇒ Object

Active AND [ mine, shared, or public ]



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

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

.publicObject



35
36
37
# File 'lib/gameui/marker.rb', line 35

def self.public
  where( is_public: true )
end

Instance Method Details

#collect(export_object) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/gameui/marker.rb', line 109

def collect export_object
  puts! export_object, "collecting in marker: |#{slug}|."

  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



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/gameui/marker.rb', line 71

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



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/gameui/marker.rb', line 91

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
    slug
    url
    version
    w
    x
    y
  |
end

#xObject

@TODO: abstract this into a module



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

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