Class: Gameui::Map
- Inherits:
-
Object
- Object
- Gameui::Map
- 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
- .empty_export ⇒ Object
- .export_key_to_class ⇒ Object
- .list(conditions = { is_trash: false }) ⇒ Object
Instance Method Summary collapse
- #breadcrumbs ⇒ Object
- #collect(export_object) ⇒ Object
- #compute_w_h ⇒ Object
-
#config ⇒ Object
Possible keys: config.description.collapsible.
-
#deleted_at ⇒ Object
@TODO: probably, abstract this.
-
#empty_export ⇒ Object
@TODO: move the export func, below, to a module.
- #empty_export_arr ⇒ Object
- #export_fields ⇒ Object
- #export_key_to_class ⇒ Object
-
#export_subtree ⇒ Object
This is the starting point vp 2022-03-12.
-
#labels ⇒ Object
Possible keys: description, map, markers, newsitems,.
- #map ⇒ Object
-
#map_slug ⇒ Object
@TODO: or self, right? and refactor this, seems N+1.
-
#newsitems_page_size ⇒ Object
endExport.
-
#w ⇒ Object
Make sure to use x,y,z and w,h as appropriate.
-
#x ⇒ Object
Make sure to use x,y,z and w,h as appropriate.
Methods included from Ish::Utils
Methods included from Ish::PremiumItem
Class Method Details
.empty_export ⇒ Object
135 |
# File 'lib/gameui/map.rb', line 135 def self.empty_export; Gameui::Map.new.empty_export; end |
.export_key_to_class ⇒ Object
171 172 173 |
# File 'lib/gameui/map.rb', line 171 def self.export_key_to_class Map.new.export_key_to_class end |
.list(conditions = { is_trash: false }) ⇒ Object
105 106 107 108 |
# File 'lib/gameui/map.rb', line 105 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
#breadcrumbs ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/gameui/map.rb', line 110 def 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
211 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 |
# File 'lib/gameui/map.rb', line 211 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_h ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/gameui/map.rb', line 85 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 |
#config ⇒ Object
Possible keys: config.description.collapsible
59 60 61 62 63 |
# File 'lib/gameui/map.rb', line 59 field :config, type: Object, default: <<~AOL { "map_panel_type": "ThreePanelV1", "studio": { "hasFloor": true, "studioLength": 2500, "studioWidth": 2500 } } AOL |
#deleted_at ⇒ Object
@TODO: probably, abstract this. vp 2022-09-20
19 |
# File 'lib/gameui/map.rb', line 19 field :deleted_at, type: Time, default: nil |
#empty_export ⇒ Object
@TODO: move the export func, below, to a module. vp 2022-09-20
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/gameui/map.rb', line 124 def empty_export return { galleries: {}, image_assets: {}, maps: {}, markers: {}, newsitems: {}, photos: {}, profiles: {}, reports: {}, videos: {}, } end |
#empty_export_arr ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/gameui/map.rb', line 137 def empty_export_arr return { galleries: [], image_assets: [], maps: [], markers: [], newsitems: [], photos: [], profiles: [], reports: [], videos: [], } end |
#export_fields ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/gameui/map.rb', line 175 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_class ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/gameui/map.rb', line 149 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_subtree ⇒ Object
This is the starting point vp 2022-03-12
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/gameui/map.rb', line 195 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 |
#labels ⇒ Object
Possible keys: description, map, markers, newsitems,
52 53 54 55 |
# File 'lib/gameui/map.rb', line 52 field :labels, type: Object, default: <<~AOL { "description":"Description", "map":"Map", "markers":"Markers", "newsitems":"Newsitems" } AOL |
#map ⇒ Object
44 45 46 |
# File 'lib/gameui/map.rb', line 44 def map ::Gameui::Map.where( slug: map_slug ).first end |
#map_slug ⇒ Object
@TODO: or self, right? and refactor this, seems N+1. vp 2022-09-13
43 |
# File 'lib/gameui/map.rb', line 43 field :map_slug |
#newsitems_page_size ⇒ Object
endExport
254 |
# File 'lib/gameui/map.rb', line 254 field :newsitems_page_size, default: 25 |
#w ⇒ Object
Make sure to use x,y,z and w,h as appropriate.
79 |
# File 'lib/gameui/map.rb', line 79 field :w, type: Integer |
#x ⇒ Object
Make sure to use x,y,z and w,h as appropriate. @TODO: abstract this into a module
74 |
# File 'lib/gameui/map.rb', line 74 field :x, type: Float |