universo-platform-3d
196 строк · 4.1 Кб
1import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2import { ApiProperty } from '@nestjs/swagger'
3import * as mongoose from 'mongoose'
4import { Document } from 'mongoose'
5import { Role, RoleSchema } from '../roles/models/role.schema'
6import { ISchemaWithRole } from '../roles/role-consumer.interface'
7import { AssetPublicData } from './asset.schema'
8import { Material } from './material.schema'
9import { Asset } from '../asset/asset.schema'
10import { Vector4AsArray } from '../option-sets/vectors'
11
12// Properties must not be undefined so that getPublicPropertiesForMongooseQuery can work
13export class MapPublicData extends AssetPublicData {
14@ApiProperty({
15example: 'Concrete_super_shiny_example'
16})
17mapName = ''
18@ApiProperty()
19heightmapAssetId = ''
20@ApiProperty()
21flatMaterialAssetId = ''
22@ApiProperty()
23cliffMaterialAssetId = ''
24@ApiProperty()
25mapSize = 512
26@ApiProperty()
27mapPrecision = 1.0
28@ApiProperty()
29heightScale = 32.0
30@ApiProperty()
31layerOffset = 0.0
32@ApiProperty()
33flatUVScale = 1.0
34@ApiProperty()
35cliffUVScale = 1.0
36@ApiProperty()
37flatCliffRatio = -0.6
38@ApiProperty()
39flatColor = [1.0, 1.0, 1.0, 1.0]
40@ApiProperty()
41cliffColor = [1.0, 1.0, 1.0, 1.0]
42@ApiProperty()
43colormapAssetId = ''
44@ApiProperty()
45colormapStrength = 1.0
46}
47
48export type MapDocument = MapAsset & Document
49
50@Schema({
51timestamps: true,
52toJSON: {
53virtuals: true
54}
55// discriminatorKey: __t <- don't uncomment this line: this line is to note that __t is the Mongoose default discriminator key that we use for simplicity rather than specifying our own discriminator key. When this schema is instantiated, __t is "MapAsset". This is DIFFERENT from assetType since we hadn't been using discriminators up until 2023-02-04 18:49:52. See https://mongoosejs.com/docs/discriminators.html#discriminator-keys. Walkthrough: https://www.loom.com/share/7e09d2777ef94368bcd5fd8c8341b5ef
56})
57export class MapAsset {
58_id: string
59@Prop({
60trim: true,
61required: true
62})
63@ApiProperty({
64example: 'Mountain_hill_example'
65})
66mapName: string
67
68/**
69* Optional properties
70*/
71@Prop({
72required: false,
73type: mongoose.Schema.Types.ObjectId,
74ref: 'Asset'
75})
76@ApiProperty()
77heightmapAssetId?: Asset
78
79@Prop({
80required: false,
81type: mongoose.Schema.Types.ObjectId,
82ref: 'Material'
83})
84@ApiProperty()
85flatMaterialAssetId?: Material
86
87@Prop({
88required: false,
89type: mongoose.Schema.Types.ObjectId,
90ref: 'Material'
91})
92@ApiProperty()
93cliffMaterialAssetId?: Material
94
95@Prop({
96required: false,
97default: 512.0,
98type: Number
99})
100@ApiProperty()
101mapSize?: number
102
103@Prop({
104required: false,
105default: 1.0,
106type: Number
107})
108@ApiProperty()
109mapPrecision?: number
110
111@Prop({
112required: false,
113default: 32.0,
114type: Number
115})
116@ApiProperty()
117heightScale?: number
118
119@Prop({
120required: false,
121default: 32.0,
122type: Number
123})
124@ApiProperty()
125layerOffset?: number
126
127@Prop({
128required: false,
129default: 1.0,
130type: Number
131})
132@ApiProperty()
133flatUVScale?: number
134
135@Prop({
136required: false,
137default: 1.0,
138type: Number
139})
140@ApiProperty()
141cliffUVScale?: number
142
143@Prop({
144required: false,
145default: -0.6
146})
147@ApiProperty()
148flatCliffRatio?: number
149
150@Prop({
151required: false,
152type: mongoose.Types.Array,
153default: [1.0, 1.0, 1.0, 1.0]
154})
155@ApiProperty()
156flatColor?: Vector4AsArray
157
158@Prop({
159required: false,
160type: mongoose.Types.Array,
161default: [1.0, 1.0, 1.0, 1.0]
162})
163@ApiProperty()
164cliffColor?: Vector4AsArray
165
166@Prop({
167required: false,
168type: mongoose.Schema.Types.ObjectId,
169ref: 'Material'
170})
171@ApiProperty()
172colormapAssetId?: mongoose.Schema.Types.ObjectId
173
174@Prop({
175required: false,
176default: 0.5,
177type: Number
178})
179@ApiProperty()
180colormapStrength?: number
181
182/**
183* START Section: ISchemaWithRole implementer
184*/
185@Prop({
186required: true,
187type: RoleSchema
188})
189@ApiProperty()
190role: Role
191/**
192* END Section: ISchemaWithRole implementer
193*/
194}
195
196export const MapSchema = SchemaFactory.createForClass(MapAsset)
197