Class: WcoGame::Location

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps, Wco::Utils
Defined in:
app/models/wco_game/location.rb

Overview

require ‘ish/premium_item’ require ‘ish/utils’

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 Wco::Utils

#export, included

Class Method Details

.empty_exportObject



137
# File 'app/models/wco_game/location.rb', line 137

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

.export_key_to_classObject



173
174
175
# File 'app/models/wco_game/location.rb', line 173

def self.export_key_to_class
  Map.new.export_key_to_class
end

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



107
108
109
110
# File 'app/models/wco_game/location.rb', line 107

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



112
113
114
115
116
117
118
119
120
# File 'app/models/wco_game/location.rb', line 112

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



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
252
# File 'app/models/wco_game/location.rb', line 213

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



87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/models/wco_game/location.rb', line 87

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



61
62
63
64
65
# File 'app/models/wco_game/location.rb', line 61

field :config, type: Object, default: "{ \"map_panel_type\": \"ThreePanelV1\",\n  \"studio\": { \"hasFloor\": true, \"studioLength\": 2500, \"studioWidth\": 2500 }\n}\n"

#empty_exportObject

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



126
127
128
129
130
131
132
133
134
135
136
# File 'app/models/wco_game/location.rb', line 126

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

#empty_export_arrObject



139
140
141
142
143
144
145
146
147
148
149
# File 'app/models/wco_game/location.rb', line 139

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

#export_fieldsObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'app/models/wco_game/location.rb', line 177

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



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'app/models/wco_game/location.rb', line 151

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



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'app/models/wco_game/location.rb', line 197

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,



54
55
56
57
# File 'app/models/wco_game/location.rb', line 54

field :labels, type: Object, default: "{ \"description\":\"Description\", \"map\":\"Map\", \"markers\":\"Markers\", \"newsitems\":\"Newsitems\"\n}\n"

#mapObject



46
47
48
# File 'app/models/wco_game/location.rb', line 46

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



45
# File 'app/models/wco_game/location.rb', line 45

field :map_slug

#wObject

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



81
# File 'app/models/wco_game/location.rb', line 81

field :w, type: Integer

#xObject

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



76
# File 'app/models/wco_game/location.rb', line 76

field :x, type: Float