forked from OpenWF/SpaceNinjaServer
		
	feat: decorating the backroom (#604)
This commit is contained in:
		
							parent
							
								
									cbdd1cd0a7
								
							
						
					
					
						commit
						95bd07b50f
					
				@ -27,7 +27,8 @@ export const getShipController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
                SkinFlavourItem: ship.SkinFlavourItem
 | 
					                SkinFlavourItem: ship.SkinFlavourItem
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        Apartment: personalRooms.Apartment
 | 
					        Apartment: personalRooms.Apartment,
 | 
				
			||||||
 | 
					        TailorShop: personalRooms.TailorShop
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (config.unlockAllShipFeatures) {
 | 
					    if (config.unlockAllShipFeatures) {
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ export const shipDecorationsController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
        res.send(placedDecoration);
 | 
					        res.send(placedDecoration);
 | 
				
			||||||
    } catch (error: unknown) {
 | 
					    } catch (error: unknown) {
 | 
				
			||||||
        if (error instanceof Error) {
 | 
					        if (error instanceof Error) {
 | 
				
			||||||
            logger.error(`error in saveLoadoutController: ${error.message}`);
 | 
					            logger.error(`error in shipDecorationsController: ${error.message}`);
 | 
				
			||||||
            res.status(400).json({ error: error.message });
 | 
					            res.status(400).json({ error: error.message });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,14 @@
 | 
				
			|||||||
import { toOid } from "@/src/helpers/inventoryHelpers";
 | 
					import { toOid } from "@/src/helpers/inventoryHelpers";
 | 
				
			||||||
import { IOrbiter, IPersonalRooms, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
 | 
					import { IOrbiter, IPersonalRooms, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
 | 
				
			||||||
import { IApartment, IGardening, IPlacedDecosDatabase, IPictureFrameInfo } from "@/src/types/shipTypes";
 | 
					import {
 | 
				
			||||||
 | 
					    IApartment,
 | 
				
			||||||
 | 
					    IFavouriteLoadoutDatabase,
 | 
				
			||||||
 | 
					    IGardening,
 | 
				
			||||||
 | 
					    IPlacedDecosDatabase,
 | 
				
			||||||
 | 
					    IPictureFrameInfo,
 | 
				
			||||||
 | 
					    IRoom,
 | 
				
			||||||
 | 
					    ITailorShopDatabase
 | 
				
			||||||
 | 
					} from "@/src/types/shipTypes";
 | 
				
			||||||
import { Schema, model } from "mongoose";
 | 
					import { Schema, model } from "mongoose";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const pictureFrameInfoSchema = new Schema<IPictureFrameInfo>(
 | 
					const pictureFrameInfoSchema = new Schema<IPictureFrameInfo>(
 | 
				
			||||||
@ -44,7 +52,7 @@ placedDecosSchema.set("toJSON", {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const roomSchema = new Schema(
 | 
					const roomSchema = new Schema<IRoom>(
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Name: String,
 | 
					        Name: String,
 | 
				
			||||||
        MaxCapacity: Number,
 | 
					        MaxCapacity: Number,
 | 
				
			||||||
@ -76,11 +84,59 @@ const orbiterSchema = new Schema<IOrbiter>(
 | 
				
			|||||||
    { _id: false }
 | 
					    { _id: false }
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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>({
 | 
					export const personalRoomsSchema = new Schema<IPersonalRooms>({
 | 
				
			||||||
    personalRoomsOwnerId: Schema.Types.ObjectId,
 | 
					    personalRoomsOwnerId: Schema.Types.ObjectId,
 | 
				
			||||||
    activeShipId: Schema.Types.ObjectId,
 | 
					    activeShipId: Schema.Types.ObjectId,
 | 
				
			||||||
    Ship: orbiterSchema,
 | 
					    Ship: orbiterSchema,
 | 
				
			||||||
    Apartment: apartmentSchema
 | 
					    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);
 | 
					export const PersonalRooms = model<IPersonalRooms, PersonalRoomsModelType>("PersonalRooms", personalRoomsSchema);
 | 
				
			||||||
 | 
				
			|||||||
@ -37,7 +37,12 @@ export const handleSetShipDecorations = async (
 | 
				
			|||||||
): Promise<IShipDecorationsResponse> => {
 | 
					): Promise<IShipDecorationsResponse> => {
 | 
				
			||||||
    const personalRooms = await getPersonalRooms(accountId);
 | 
					    const personalRooms = await getPersonalRooms(accountId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const rooms = placedDecoration.IsApartment ? personalRooms.Apartment.Rooms : personalRooms.Ship.Rooms;
 | 
					    const rooms =
 | 
				
			||||||
 | 
					        placedDecoration.BootLocation == "SHOP"
 | 
				
			||||||
 | 
					            ? personalRooms.TailorShop.Rooms
 | 
				
			||||||
 | 
					            : placedDecoration.IsApartment
 | 
				
			||||||
 | 
					              ? personalRooms.Apartment.Rooms
 | 
				
			||||||
 | 
					              : personalRooms.Ship.Rooms;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const roomToPlaceIn = rooms.find(room => room.Name === placedDecoration.Room);
 | 
					    const roomToPlaceIn = rooms.find(room => room.Name === placedDecoration.Room);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,9 +1,9 @@
 | 
				
			|||||||
import { IApartment, IRooms, IPlacedDecosDatabase, TBootLocation } from "@/src/types/shipTypes";
 | 
					import { IApartment, IRoom, IPlacedDecosDatabase, ITailorShop, TBootLocation } from "@/src/types/shipTypes";
 | 
				
			||||||
import { Model, Types } from "mongoose";
 | 
					import { Model, Types } from "mongoose";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IOrbiter {
 | 
					export interface IOrbiter {
 | 
				
			||||||
    Features: string[];
 | 
					    Features: string[];
 | 
				
			||||||
    Rooms: IRooms[];
 | 
					    Rooms: IRoom[];
 | 
				
			||||||
    ContentUrlSignature: string;
 | 
					    ContentUrlSignature: string;
 | 
				
			||||||
    BootLocation?: TBootLocation;
 | 
					    BootLocation?: TBootLocation;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -13,6 +13,7 @@ export interface IPersonalRooms {
 | 
				
			|||||||
    activeShipId: Types.ObjectId;
 | 
					    activeShipId: Types.ObjectId;
 | 
				
			||||||
    Ship: IOrbiter;
 | 
					    Ship: IOrbiter;
 | 
				
			||||||
    Apartment: IApartment;
 | 
					    Apartment: IApartment;
 | 
				
			||||||
 | 
					    TailorShop: ITailorShop;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type RoomsType = { Name: string; MaxCapacity: number; PlacedDecos: Types.DocumentArray<IPlacedDecosDatabase> };
 | 
					export type RoomsType = { Name: string; MaxCapacity: number; PlacedDecos: Types.DocumentArray<IPlacedDecosDatabase> };
 | 
				
			||||||
@ -24,6 +25,9 @@ export type PersonalRoomsDocumentProps = {
 | 
				
			|||||||
    Apartment: Omit<IApartment, "Rooms"> & {
 | 
					    Apartment: Omit<IApartment, "Rooms"> & {
 | 
				
			||||||
        Rooms: RoomsType[];
 | 
					        Rooms: RoomsType[];
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					    TailorShop: Omit<ITailorShop, "Rooms"> & {
 | 
				
			||||||
 | 
					        Rooms: RoomsType[];
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// eslint-disable-next-line @typescript-eslint/ban-types
 | 
					// eslint-disable-next-line @typescript-eslint/ban-types
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ export interface IGetShipResponse {
 | 
				
			|||||||
    ShipOwnerId: string;
 | 
					    ShipOwnerId: string;
 | 
				
			||||||
    Ship: IShip;
 | 
					    Ship: IShip;
 | 
				
			||||||
    Apartment: IApartment;
 | 
					    Apartment: IApartment;
 | 
				
			||||||
 | 
					    TailorShop: ITailorShop;
 | 
				
			||||||
    LoadOutInventory: { LoadOutPresets: ILoadoutClient };
 | 
					    LoadOutInventory: { LoadOutPresets: ILoadoutClient };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -26,7 +27,7 @@ export interface IShip {
 | 
				
			|||||||
    Features: string[];
 | 
					    Features: string[];
 | 
				
			||||||
    ShipId: IOid;
 | 
					    ShipId: IOid;
 | 
				
			||||||
    ShipInterior: IShipInterior;
 | 
					    ShipInterior: IShipInterior;
 | 
				
			||||||
    Rooms: IRooms[];
 | 
					    Rooms: IRoom[];
 | 
				
			||||||
    ContentUrlSignature: string;
 | 
					    ContentUrlSignature: string;
 | 
				
			||||||
    BootLocation?: TBootLocation;
 | 
					    BootLocation?: TBootLocation;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -41,7 +42,7 @@ export interface IShipDatabase {
 | 
				
			|||||||
    SkinFlavourItem?: string;
 | 
					    SkinFlavourItem?: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IRooms {
 | 
					export interface IRoom {
 | 
				
			||||||
    Name: string;
 | 
					    Name: string;
 | 
				
			||||||
    MaxCapacity: number;
 | 
					    MaxCapacity: number;
 | 
				
			||||||
    PlacedDecos?: IPlacedDecosDatabase[];
 | 
					    PlacedDecos?: IPlacedDecosDatabase[];
 | 
				
			||||||
@ -62,7 +63,7 @@ export interface IGardening {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
export interface IApartment {
 | 
					export interface IApartment {
 | 
				
			||||||
    Gardening: IGardening;
 | 
					    Gardening: IGardening;
 | 
				
			||||||
    Rooms: IRooms[];
 | 
					    Rooms: IRoom[];
 | 
				
			||||||
    FavouriteLoadouts: string[];
 | 
					    FavouriteLoadouts: string[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -102,7 +103,8 @@ export interface IShipDecorationsRequest {
 | 
				
			|||||||
    Pos: [number, number, number];
 | 
					    Pos: [number, number, number];
 | 
				
			||||||
    Rot: [number, number, number];
 | 
					    Rot: [number, number, number];
 | 
				
			||||||
    Room: string;
 | 
					    Room: string;
 | 
				
			||||||
    IsApartment: boolean;
 | 
					    BootLocation?: TBootLocation;
 | 
				
			||||||
 | 
					    IsApartment?: boolean;
 | 
				
			||||||
    RemoveId?: string;
 | 
					    RemoveId?: string;
 | 
				
			||||||
    MoveId?: string;
 | 
					    MoveId?: string;
 | 
				
			||||||
    OldRoom?: string;
 | 
					    OldRoom?: string;
 | 
				
			||||||
@ -112,7 +114,7 @@ export interface IShipDecorationsRequest {
 | 
				
			|||||||
export interface IShipDecorationsResponse {
 | 
					export interface IShipDecorationsResponse {
 | 
				
			||||||
    DecoId?: string;
 | 
					    DecoId?: string;
 | 
				
			||||||
    Room?: string;
 | 
					    Room?: string;
 | 
				
			||||||
    IsApartment: boolean;
 | 
					    IsApartment?: boolean;
 | 
				
			||||||
    MaxCapacityIncrease?: number;
 | 
					    MaxCapacityIncrease?: number;
 | 
				
			||||||
    OldRoom?: string;
 | 
					    OldRoom?: string;
 | 
				
			||||||
    NewRoom?: string;
 | 
					    NewRoom?: string;
 | 
				
			||||||
@ -141,3 +143,25 @@ export interface IPictureFrameInfo {
 | 
				
			|||||||
    TextColorB: number;
 | 
					    TextColorB: number;
 | 
				
			||||||
    TextOrientation: number;
 | 
					    TextOrientation: number;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface IFavouriteLoadout {
 | 
				
			||||||
 | 
					    Tag: string;
 | 
				
			||||||
 | 
					    LoadoutId: IOid;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface IFavouriteLoadoutDatabase {
 | 
				
			||||||
 | 
					    Tag: string;
 | 
				
			||||||
 | 
					    LoadoutId: Types.ObjectId;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface ITailorShopDatabase {
 | 
				
			||||||
 | 
					    FavouriteLoadouts: IFavouriteLoadoutDatabase[];
 | 
				
			||||||
 | 
					    CustomJson: "{}"; // ???
 | 
				
			||||||
 | 
					    LevelDecosVisible: boolean;
 | 
				
			||||||
 | 
					    Rooms: IRoom[];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface ITailorShop extends Omit<ITailorShopDatabase, "FavouriteLoadouts"> {
 | 
				
			||||||
 | 
					    FavouriteLoadouts: IFavouriteLoadout[];
 | 
				
			||||||
 | 
					    Colors: []; // ???
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user