Class: Gameui::Map

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

Constant Summary collapse

RATED_OPTIONS =
[ 'pg-13', 'r', 'nc-17' ]
ORDERING_TYPE_ALPHABETIC =
'alphabetic'
ORDERING_TYPE_CUSTOM =
'custom'
ORDERING_TYPE_TIMESTAMP =
'timestamp'
ORDERING_TYPES =
[ ORDERING_TYPE_ALPHABETIC, ORDERING_TYPE_CUSTOM, ORDERING_TYPE_TIMESTAMP ]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ish::Utils

#export

Methods included from Ish::PremiumItem

included, #is_premium

Class Method Details

.empty_exportObject



136
# File 'lib/gameui/map.rb', line 136

def self.empty_export; Gameui::Map.new.empty_export; end

.export_key_to_classObject



172
173
174
# File 'lib/gameui/map.rb', line 172

def self.export_key_to_class
  Map.new.export_key_to_class
end

.list(conditions = { is_trash: false }) ⇒ Object



106
107
108
109
# File 'lib/gameui/map.rb', line 106

def self.list conditions = { is_trash: false }
  out = self.order_by( created_at: :desc )
  [[nil, nil]] + out.map { |item| [ item.name, item.id.to_s ] }
end

Instance Method Details



111
112
113
114
115
116
117
118
119
# File 'lib/gameui/map.rb', line 111

def breadcrumbs
  out = [{ name: self.name, slug: self.slug, link: false }]
  p = self.parent
  while p
    out.push({ name: p.name, slug: p.slug })
    p = p.parent
  end
  out.reverse
end

#collect(export_object) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/gameui/map.rb', line 212

def collect export_object
  map = self
  export_object[:maps][map.id.to_s] = map.id.to_s

  if map.markers.present?
    map.markers.map do |marker|
      id = marker.id.to_s
      if !export_object[:markers][id]
        marker.collect( export_object )
      end
      export_object[:markers][id] = id
    end
  end

  if map.newsitems.present?
    map.newsitems.map do |newsitem|
      id = newsitem.id.to_s
      export_object[:newsitems][id] = id
      newsitem.collect export_object
    end
  end

  ## @TODO: maybe implement this later, maybe not. _vp_ 2022-03-12
  # if map.childs.present?
  #   export_object[:maps].push( map.childs.map &:id )
  #   map.childs.map do |child|
  #     child.collect export_object
  #   end
  # end

  if map.creator_profile.present?
    export_object[:profiles][map.creator_profile.id.to_s] = map.creator_profile.id.to_s
  end

  if map.image.present?
    export_object[:image_assets][map.image.id.to_s] = map.image.id.to_s
  end

  export_object
end

#compute_w_hObject



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gameui/map.rb', line 86

def compute_w_h
  return if !image ## @TODO: test this

  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

#configObject

Possible keys: config.description.collapsible



60
61
62
63
64
# File 'lib/gameui/map.rb', line 60

field :config, type: Object, default: <<~AOL
  { "map_panel_type": "ThreePanelV1",
    "studio": { "hasFloor": true, "studioLength": 2500, "studioWidth": 2500 }
  }
AOL

#deleted_atObject

@TODO: probably, abstract this. vp 2022-09-20



19
# File 'lib/gameui/map.rb', line 19

field :deleted_at, type: Time, default: nil

#empty_exportObject

@TODO: move the export func, below, to a module. vp 2022-09-20



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/gameui/map.rb', line 125

def empty_export
  return {
    galleries: {},
    image_assets: {},
    maps: {}, markers: {},
    newsitems: {},
    photos: {}, profiles: {},
    reports: {},
    videos: {},
  }
end

#empty_export_arrObject



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/gameui/map.rb', line 138

def empty_export_arr
  return {
    galleries: [],
    image_assets: [],
    maps: [], markers: [],
    newsitems: [],
    photos: [], profiles: [],
    reports: [],
    videos: [],
  }
end

#export_fieldsObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/gameui/map.rb', line 176

def export_fields
  %w|
    creator_profile_id config
    deleted_at description
    h
    is_public
    labels
    map_slug
    name
    ordering_type
    parent_slug
    rated
    slug
    version
    w
  |
end

#export_key_to_classObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/gameui/map.rb', line 150

def export_key_to_class
  return {
    galleries: 'Gallery',
    image_assets: 'Ish::ImageAsset',
    maps: 'Gameui::Map',
    markers: 'Gameui::Marker',
    newsitems: 'Newsitem',
    photos: 'Photo',
    profiles: 'Ish::UserProfile',
    reports: 'Report',
    videos: 'Video',
    # 'galleries' => 'Gallery',
    # 'image_assets' => 'Ish::ImageAsset',
    # 'maps' => 'Gameui::Map',
    # 'markers' => 'Gameui::Marker',
    # 'newsitems' => 'Newsitem',
    # 'photos' => 'Photo',
    # 'profiles' => 'Ish::UserProfile',
    # 'reports' => 'Report',
    # 'videos' => 'Video',
  }.with_indifferent_access
end

#export_subtreeObject

This is the starting point vp 2022-03-12



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/gameui/map.rb', line 196

def export_subtree
  collected = collect(empty_export)
  exportable = empty_export_arr
  collected.map do |k, v|
    if v.present?
      v.map do |id|
        id = id[0]
        item = export_key_to_class[k].constantize.unscoped.find id
        export = item.export
        exportable[k].push( export )
      end
    end
  end
  JSON.pretty_generate exportable
end

#labelsObject

Possible keys: description, map, markers, newsitems,



53
54
55
56
# File 'lib/gameui/map.rb', line 53

field :labels, type: Object, default: <<~AOL
  { "description":"Description", "map":"Map", "markers":"Markers", "newsitems":"Newsitems"
  }
AOL

#mapObject



45
46
47
# File 'lib/gameui/map.rb', line 45

def map
  ::Gameui::Map.where( slug: map_slug ).first
end

#map_slugObject

@TODO: or self, right? and refactor this, seems N+1. vp 2022-09-13



44
# File 'lib/gameui/map.rb', line 44

field :map_slug

#newsitems_page_sizeObject

endExport



255
# File 'lib/gameui/map.rb', line 255

field :newsitems_page_size, default: 25

#wObject

Make sure to use x,y,z and w,h as appropriate.



80
# File 'lib/gameui/map.rb', line 80

field :w, type: Integer

#xObject

Make sure to use x,y,z and w,h as appropriate. @TODO: abstract this into a module



75
# File 'lib/gameui/map.rb', line 75

field :x, type: Float