universo-platform-3d

Форк
0
352 строки · 7.5 Кб
1
import * as mongoose from 'mongoose'
2
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
3
import { Document } from 'mongoose'
4
import { User, UserPublicData } from '../user/user.schema'
5
import { ASSET_TYPE } from '../option-sets/asset-type'
6
import { ApiProperty } from '@nestjs/swagger'
7
import { Vector4AsArray } from '../option-sets/vectors'
8
import { CustomData } from '../custom-data/models/custom-data.schema'
9
import {
10
  PurchaseOption,
11
  PurchaseOptionSchema
12
} from '../marketplace/purchase-option.subdocument.schema'
13
import {
14
  LicenseSchema,
15
  License
16
} from '../marketplace/license.subdocument.schema'
17
import { Role, RoleSchema } from '../roles/models/role.schema'
18
import { Tags, TagsSchema } from '../tag/models/tags.schema'
19
import { ObjectId } from 'mongodb'
20

21
export type AssetDiscriminators = 'MapAsset' | 'Material' | 'Texture'
22

23
// Properties must not be undefined so that getPublicPropertiesForMongooseQuery can work
24
export class AssetPublicData {
25
  @ApiProperty() // @ApiProperty must be included to be exposed by the API and flow to FE codegen
26
  _id = '' // Must not be undefined
27
  @ApiProperty()
28
  createdAt = new Date()
29
  @ApiProperty()
30
  updatedAt = new Date()
31
  @ApiProperty()
32
  name = ''
33
  @ApiProperty({
34
    enum: ASSET_TYPE
35
  })
36
  assetType = ASSET_TYPE.IMAGE
37
  @ApiProperty()
38
  description = ''
39
  @ApiProperty()
40
  mirrorPublicLibrary = false
41

42
  /**
43
   * @deprecated Use .role property instead
44
   * @date 2023-05-05 09:25
45
   */
46
  @ApiProperty({
47
    type: UserPublicData,
48
    description: 'Deprecated: use .role property instead'
49
  })
50
  owner = new UserPublicData()
51

52
  @ApiProperty({
53
    type: [PurchaseOption],
54
    required: false,
55
    description:
56
      'Array of PurchaseOptions, e.g. for sale at xyz price with abc license. Each purchaseOption has an enabled boolean'
57
  })
58
  purchaseOptions = []
59

60
  @ApiProperty({
61
    type: UserPublicData
62
  })
63
  creator = new UserPublicData()
64
  @ApiProperty()
65
  public = true
66
  @ApiProperty()
67
  thumbnail = ''
68
  @ApiProperty({ type: Tags })
69
  tags = {}
70
  // Transform properties.
71
  @ApiProperty()
72
  initPositionX = 0
73
  @ApiProperty()
74
  initPositionZ = 0
75
  @ApiProperty()
76
  initRotationX = 0
77
  @ApiProperty()
78
  initRotationY = 0
79
  @ApiProperty()
80
  initRotationZ = 0
81
  @ApiProperty()
82
  initScaleX = 0
83
  @ApiProperty()
84
  initScaleY = 0
85
  @ApiProperty()
86
  initScaleZ = 0
87
  // Physics properties.
88
  @ApiProperty()
89
  collisionEnabled = true
90
  @ApiProperty()
91
  staticEnabled = true
92
  @ApiProperty()
93
  massKg = 1.0
94
  @ApiProperty()
95
  gravityScale = 1.0
96
  // Material properties.
97
  @ApiProperty()
98
  objectColor = [1.0, 1.0, 1.0, 1.0]
99
  @ApiProperty()
100
  isSoftDeleted: boolean
101
  @ApiProperty()
102
  softDeletedAt: string
103
  @ApiProperty()
104
  fileHash: string
105
  @ApiProperty()
106
  purchasedParentAssetId: string
107
  // asset pack properties
108
  @ApiProperty()
109
  assetPack: boolean
110
  @ApiProperty()
111
  assetsInPack: ObjectId[]
112
}
113

114
export type AssetDocument = Asset & Document // Note: we also have subclasses/disciminators for materials and textures (as of 2023-02-04 20:18:08). Walkthrough: https://www.loom.com/share/7e09d2777ef94368bcd5fd8c8341b5ef
115

116
@Schema({
117
  timestamps: true,
118
  toJSON: {
119
    virtuals: true
120
  }
121
})
122
export class Asset {
123
  @ApiProperty()
124
  _id: string
125

126
  @ApiProperty()
127
  createdAt: Date // this is managed by mongoose timestamps: true, but defining it here so types will align
128
  @ApiProperty()
129
  updatedAt: Date // this is managed by mongoose timestamps: true, but defining it here so types will align
130

131
  @Prop({
132
    required: true
133
  })
134
  @ApiProperty()
135
  name: string
136

137
  @Prop({
138
    required: true,
139
    default: () => ASSET_TYPE.PANEL,
140
    enum: ASSET_TYPE,
141
    type: String
142
  })
143
  @ApiProperty({ enum: ASSET_TYPE })
144
  assetType: string
145

146
  @Prop({
147
    required: false,
148
    default: () => ASSET_TYPE.PANEL,
149
    enum: ASSET_TYPE,
150
    type: String
151
  })
152
  @ApiProperty({ enum: ASSET_TYPE })
153
  gameplayType: string
154

155
  @Prop()
156
  @ApiProperty()
157
  description: string
158

159
  @Prop({
160
    required: true,
161
    default: false
162
  })
163
  @ApiProperty()
164
  mirrorPublicLibrary: boolean // also see thirdPartySource tag
165

166
  @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'CustomData' })
167
  @ApiProperty()
168
  customData: CustomData
169

170
  /**
171
   * @deprecated Use .role property instead
172
   * @date 2023-05-05 09:25
173
   */
174
  @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User', required: false })
175
  @ApiProperty({
176
    description: 'Deprecated: use .role property instead'
177
  })
178
  owner: User
179

180
  @Prop({ type: [PurchaseOptionSchema], required: false })
181
  @ApiProperty({
182
    type: () => PurchaseOption,
183
    description:
184
      'Array of PurchaseOptions, e.g. for sale at xyz price with abc license. Each purchaseOption has an enabled boolean'
185
  })
186
  purchaseOptions?: PurchaseOption[]
187

188
  @Prop({ type: LicenseSchema, required: false })
189
  @ApiProperty({
190
    type: () => License,
191
    description: 'License for the entity. By default, a creator has all rights.'
192
  })
193
  license?: License
194

195
  @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true })
196
  @ApiProperty()
197
  creator: User
198

199
  /**
200
   * @deprecated Use .role property instead
201
   * @date 2023-05-05 09:25
202
   */
203
  @Prop({
204
    required: true,
205
    default: true
206
  })
207
  @ApiProperty({
208
    description: 'Deprecated: use .role property instead'
209
  })
210
  public: boolean // should the asset be viewable by public?
211

212
  @Prop(String)
213
  @ApiProperty()
214
  thumbnail: string
215

216
  @Prop()
217
  @ApiProperty()
218
  currentFile: string
219

220
  @Prop({ required: false })
221
  @ApiProperty()
222
  fileHash?: string
223

224
  // Transform properties.
225
  @Prop({})
226
  @ApiProperty()
227
  initPositionX: number
228

229
  @Prop({})
230
  @ApiProperty()
231
  initPositionY: number
232

233
  @Prop({})
234
  @ApiProperty()
235
  initPositionZ: number
236

237
  @Prop({
238
    default: 0
239
  })
240
  @ApiProperty()
241
  initRotationX: number
242

243
  @Prop({
244
    default: 0
245
  })
246
  @ApiProperty()
247
  initRotationY: number
248

249
  @Prop({
250
    default: 0
251
  })
252
  @ApiProperty()
253
  initRotationZ: number
254

255
  @Prop({
256
    default: 0
257
  })
258
  @ApiProperty()
259
  initScaleX: number
260

261
  @Prop({
262
    default: 0
263
  })
264
  @ApiProperty()
265
  initScaleY: number
266

267
  @Prop({
268
    default: 0
269
  })
270
  @ApiProperty()
271
  initScaleZ: number
272

273
  // Physics properties.
274
  @Prop({
275
    default: true
276
  })
277
  @ApiProperty()
278
  collisionEnabled: boolean
279

280
  @Prop({
281
    default: true
282
  })
283
  @ApiProperty()
284
  staticEnabled: boolean
285

286
  @Prop({
287
    default: 1.0
288
  })
289
  @ApiProperty()
290
  massKg: number
291

292
  @Prop({
293
    default: 1.0
294
  })
295
  @ApiProperty()
296
  gravityScale: number
297

298
  @Prop({ type: TagsSchema, required: false, default: {} })
299
  @ApiProperty()
300
  tags: Tags
301

302
  @Prop({ type: Boolean, required: false })
303
  @ApiProperty()
304
  isSoftDeleted: boolean
305

306
  @Prop({ type: Date, required: false })
307
  @ApiProperty()
308
  softDeletedAt: string
309

310
  @Prop({ type: Boolean, required: false })
311
  @ApiProperty()
312
  isEquipable: boolean
313

314
  // Material properties.
315
  @Prop({
316
    default: [1.0, 1.0, 1.0, 1.0],
317
    type: mongoose.Types.Array
318
  })
319
  @ApiProperty()
320
  objectColor: Vector4AsArray
321

322
  /**
323
   * START Section: ISchemaWithRole implementer
324
   */
325
  @Prop({
326
    required: true,
327
    type: RoleSchema
328
  })
329
  @ApiProperty()
330
  role: Role
331
  /**
332
   * END Section: ISchemaWithRole implementer
333
   */
334
  // If the asset was purchased, this is the ID of that original asset since assets are copied upon purchase
335
  @Prop({ type: String, required: false })
336
  @ApiProperty()
337
  purchasedParentAssetId: string
338

339
  @Prop({ type: Boolean, required: false, default: undefined })
340
  @ApiProperty()
341
  assetPack: boolean
342

343
  @Prop({
344
    type: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Asset' }],
345
    required: false,
346
    default: undefined
347
  })
348
  @ApiProperty()
349
  assetsInPack: ObjectId[]
350
}
351

352
export const AssetSchema = SchemaFactory.createForClass(Asset)
353

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.