SpaceNinjaServer/src/models/personalRoomsModel.ts

143 lines
3.5 KiB
TypeScript
Raw Normal View History

import { toOid } from "@/src/helpers/inventoryHelpers";
import { IOrbiter, IPersonalRooms, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
2024-12-22 20:32:19 +01:00
import {
IApartment,
IFavouriteLoadoutDatabase,
IGardening,
IPlacedDecosDatabase,
IPictureFrameInfo,
IRoom,
ITailorShopDatabase
} from "@/src/types/shipTypes";
import { Schema, model } from "mongoose";
const pictureFrameInfoSchema = new Schema<IPictureFrameInfo>(
{
Image: String,
Filter: String,
XOffset: Number,
YOffset: Number,
Scale: Number,
InvertX: Boolean,
InvertY: Boolean,
ColorCorrection: Number,
Text: String,
TextScale: Number,
TextColorA: Number,
TextColorB: Number,
TextOrientation: Number
},
{ id: false, _id: false }
);
const placedDecosSchema = new Schema<IPlacedDecosDatabase>(
{
Type: String,
Pos: [Number],
2024-06-15 17:39:13 +02:00
Rot: [Number],
Scale: Number,
PictureFrameInfo: { type: pictureFrameInfoSchema, default: undefined }
},
{ id: false }
);
placedDecosSchema.virtual("id").get(function (this: IPlacedDecosDatabase) {
return toOid(this._id);
});
placedDecosSchema.set("toJSON", {
virtuals: true,
transform(_document, returnedObject) {
delete returnedObject._id;
}
});
2024-12-22 20:32:19 +01:00
const roomSchema = new Schema<IRoom>(
{
Name: String,
MaxCapacity: Number,
PlacedDecos: [placedDecosSchema]
},
{ _id: false }
);
const gardeningSchema = new Schema<IGardening>({
Planters: [Schema.Types.Mixed] //TODO: add when implementing gardening
});
const apartmentSchema = new Schema<IApartment>(
{
Rooms: [roomSchema],
FavouriteLoadouts: [Schema.Types.Mixed],
Gardening: gardeningSchema
},
{ _id: false }
);
const orbiterSchema = new Schema<IOrbiter>(
2024-05-06 15:39:27 +02:00
{
Features: [String],
Rooms: [roomSchema],
ContentUrlSignature: String,
BootLocation: String
},
{ _id: false }
);
2024-12-22 20:32:19 +01:00
const favouriteLoadoutSchema = new Schema<IFavouriteLoadoutDatabase>(
{
Tag: String,
LoadoutId: Schema.Types.ObjectId
},
{ _id: false }
);
favouriteLoadoutSchema.set("toJSON", {
virtuals: true,
transform(_document, returnedObject) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
returnedObject.LoadoutId = toOid(returnedObject.LoadoutId);
}
});
const tailorShopSchema = new Schema<ITailorShopDatabase>(
{
FavouriteLoadouts: [favouriteLoadoutSchema],
CustomJson: String,
LevelDecosVisible: Boolean,
Rooms: [roomSchema]
},
{ _id: false }
);
const tailorShopDefault: ITailorShopDatabase = {
FavouriteLoadouts: [],
CustomJson: "{}",
LevelDecosVisible: true,
Rooms: [
{
Name: "LabRoom",
MaxCapacity: 4000
},
{
Name: "LivingQuartersRoom",
MaxCapacity: 3000
},
{
Name: "HelminthRoom",
MaxCapacity: 2000
}
]
};
export const personalRoomsSchema = new Schema<IPersonalRooms>({
personalRoomsOwnerId: Schema.Types.ObjectId,
activeShipId: Schema.Types.ObjectId,
Ship: orbiterSchema,
2024-12-22 20:32:19 +01:00
Apartment: apartmentSchema,
TailorShop: {
type: tailorShopSchema,
default: tailorShopDefault as any as undefined // Yeah, this is bad, but mongoose types here are wrong.
}
});
export const PersonalRooms = model<IPersonalRooms, PersonalRoomsModelType>("PersonalRooms", personalRoomsSchema);