XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

feat: decorating the backroom (#604)

95bd07b5
Sainan <sainan@calamity.inc>
提交于

代码差异

6 个文件 +103 -13
Modified src/controllers/api/getShipController.ts +2 -1
@@ -27,7 +27,8 @@ export const getShipController: RequestHandler = async (req, res) => {
27 27 SkinFlavourItem: ship.SkinFlavourItem
28 28 }
29 29 },
30 Apartment: personalRooms.Apartment
30 Apartment: personalRooms.Apartment,
31 TailorShop: personalRooms.TailorShop
31 32 };
32 33
33 34 if (config.unlockAllShipFeatures) {
Modified src/controllers/api/shipDecorationsController.ts +1 -1
@@ -13,7 +13,7 @@ export const shipDecorationsController: RequestHandler = async (req, res) => {
13 13 res.send(placedDecoration);
14 14 } catch (error: unknown) {
15 15 if (error instanceof Error) {
16 logger.error(`error in saveLoadoutController: ${error.message}`);
16 logger.error(`error in shipDecorationsController: ${error.message}`);
17 17 res.status(400).json({ error: error.message });
18 18 }
19 19 }
Modified src/models/personalRoomsModel.ts +59 -3
@@ -1,6 +1,14 @@
1 1 import { toOid } from "@/src/helpers/inventoryHelpers";
2 2 import { IOrbiter, IPersonalRooms, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
3 import { IApartment, IGardening, IPlacedDecosDatabase, IPictureFrameInfo } from "@/src/types/shipTypes";
3 import {
4 IApartment,
5 IFavouriteLoadoutDatabase,
6 IGardening,
7 IPlacedDecosDatabase,
8 IPictureFrameInfo,
9 IRoom,
10 ITailorShopDatabase
11 } from "@/src/types/shipTypes";
4 12 import { Schema, model } from "mongoose";
5 13
6 14 const pictureFrameInfoSchema = new Schema<IPictureFrameInfo>(
@@ -44,7 +52,7 @@ placedDecosSchema.set("toJSON", {
44 52 }
45 53 });
46 54
47 const roomSchema = new Schema(
55 const roomSchema = new Schema<IRoom>(
48 56 {
49 57 Name: String,
50 58 MaxCapacity: Number,
@@ -76,11 +84,59 @@ const orbiterSchema = new Schema<IOrbiter>(
76 84 { _id: false }
77 85 );
78 86
87 const favouriteLoadoutSchema = new Schema<IFavouriteLoadoutDatabase>(
88 {
89 Tag: String,
90 LoadoutId: Schema.Types.ObjectId
91 },
92 { _id: false }
93 );
94 favouriteLoadoutSchema.set("toJSON", {
95 virtuals: true,
96 transform(_document, returnedObject) {
97 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
98 returnedObject.LoadoutId = toOid(returnedObject.LoadoutId);
99 }
100 });
101
102 const tailorShopSchema = new Schema<ITailorShopDatabase>(
103 {
104 FavouriteLoadouts: [favouriteLoadoutSchema],
105 CustomJson: String,
106 LevelDecosVisible: Boolean,
107 Rooms: [roomSchema]
108 },
109 { _id: false }
110 );
111 const tailorShopDefault: ITailorShopDatabase = {
112 FavouriteLoadouts: [],
113 CustomJson: "{}",
114 LevelDecosVisible: true,
115 Rooms: [
116 {
117 Name: "LabRoom",
118 MaxCapacity: 4000
119 },
120 {
121 Name: "LivingQuartersRoom",
122 MaxCapacity: 3000
123 },
124 {
125 Name: "HelminthRoom",
126 MaxCapacity: 2000
127 }
128 ]
129 };
130
79 131 export const personalRoomsSchema = new Schema<IPersonalRooms>({
80 132 personalRoomsOwnerId: Schema.Types.ObjectId,
81 133 activeShipId: Schema.Types.ObjectId,
82 134 Ship: orbiterSchema,
83 Apartment: apartmentSchema
135 Apartment: apartmentSchema,
136 TailorShop: {
137 type: tailorShopSchema,
138 default: tailorShopDefault as any as undefined // Yeah, this is bad, but mongoose types here are wrong.
139 }
84 140 });
85 141
86 142 export const PersonalRooms = model<IPersonalRooms, PersonalRoomsModelType>("PersonalRooms", personalRoomsSchema);
Modified src/services/shipCustomizationsService.ts +6 -1
@@ -37,7 +37,12 @@ export const handleSetShipDecorations = async (
37 37 ): Promise<IShipDecorationsResponse> => {
38 38 const personalRooms = await getPersonalRooms(accountId);
39 39
40 const rooms = placedDecoration.IsApartment ? personalRooms.Apartment.Rooms : personalRooms.Ship.Rooms;
40 const rooms =
41 placedDecoration.BootLocation == "SHOP"
42 ? personalRooms.TailorShop.Rooms
43 : placedDecoration.IsApartment
44 ? personalRooms.Apartment.Rooms
45 : personalRooms.Ship.Rooms;
41 46
42 47 const roomToPlaceIn = rooms.find(room => room.Name === placedDecoration.Room);
43 48
Modified src/types/personalRoomsTypes.ts +6 -2
@@ -1,9 +1,9 @@
1 import { IApartment, IRooms, IPlacedDecosDatabase, TBootLocation } from "@/src/types/shipTypes";
1 import { IApartment, IRoom, IPlacedDecosDatabase, ITailorShop, TBootLocation } from "@/src/types/shipTypes";
2 2 import { Model, Types } from "mongoose";
3 3
4 4 export interface IOrbiter {
5 5 Features: string[];
6 Rooms: IRooms[];
6 Rooms: IRoom[];
7 7 ContentUrlSignature: string;
8 8 BootLocation?: TBootLocation;
9 9 }
@@ -13,6 +13,7 @@ export interface IPersonalRooms {
13 13 activeShipId: Types.ObjectId;
14 14 Ship: IOrbiter;
15 15 Apartment: IApartment;
16 TailorShop: ITailorShop;
16 17 }
17 18
18 19 export type RoomsType = { Name: string; MaxCapacity: number; PlacedDecos: Types.DocumentArray<IPlacedDecosDatabase> };
@@ -24,6 +25,9 @@ export type PersonalRoomsDocumentProps = {
24 25 Apartment: Omit<IApartment, "Rooms"> & {
25 26 Rooms: RoomsType[];
26 27 };
28 TailorShop: Omit<ITailorShop, "Rooms"> & {
29 Rooms: RoomsType[];
30 };
27 31 };
28 32
29 33 // eslint-disable-next-line @typescript-eslint/ban-types
Modified src/types/shipTypes.ts +29 -5
@@ -7,6 +7,7 @@ export interface IGetShipResponse {
7 7 ShipOwnerId: string;
8 8 Ship: IShip;
9 9 Apartment: IApartment;
10 TailorShop: ITailorShop;
10 11 LoadOutInventory: { LoadOutPresets: ILoadoutClient };
11 12 }
12 13
@@ -26,7 +27,7 @@ export interface IShip {
26 27 Features: string[];
27 28 ShipId: IOid;
28 29 ShipInterior: IShipInterior;
29 Rooms: IRooms[];
30 Rooms: IRoom[];
30 31 ContentUrlSignature: string;
31 32 BootLocation?: TBootLocation;
32 33 }
@@ -41,7 +42,7 @@ export interface IShipDatabase {
41 42 SkinFlavourItem?: string;
42 43 }
43 44
44 export interface IRooms {
45 export interface IRoom {
45 46 Name: string;
46 47 MaxCapacity: number;
47 48 PlacedDecos?: IPlacedDecosDatabase[];
@@ -62,7 +63,7 @@ export interface IGardening {
62 63 }
63 64 export interface IApartment {
64 65 Gardening: IGardening;
65 Rooms: IRooms[];
66 Rooms: IRoom[];
66 67 FavouriteLoadouts: string[];
67 68 }
68 69
@@ -102,7 +103,8 @@ export interface IShipDecorationsRequest {
102 103 Pos: [number, number, number];
103 104 Rot: [number, number, number];
104 105 Room: string;
105 IsApartment: boolean;
106 BootLocation?: TBootLocation;
107 IsApartment?: boolean;
106 108 RemoveId?: string;
107 109 MoveId?: string;
108 110 OldRoom?: string;
@@ -112,7 +114,7 @@ export interface IShipDecorationsRequest {
112 114 export interface IShipDecorationsResponse {
113 115 DecoId?: string;
114 116 Room?: string;
115 IsApartment: boolean;
117 IsApartment?: boolean;
116 118 MaxCapacityIncrease?: number;
117 119 OldRoom?: string;
118 120 NewRoom?: string;
@@ -141,3 +143,25 @@ export interface IPictureFrameInfo {
141 143 TextColorB: number;
142 144 TextOrientation: number;
143 145 }
146
147 export interface IFavouriteLoadout {
148 Tag: string;
149 LoadoutId: IOid;
150 }
151
152 export interface IFavouriteLoadoutDatabase {
153 Tag: string;
154 LoadoutId: Types.ObjectId;
155 }
156
157 export interface ITailorShopDatabase {
158 FavouriteLoadouts: IFavouriteLoadoutDatabase[];
159 CustomJson: "{}"; // ???
160 LevelDecosVisible: boolean;
161 Rooms: IRoom[];
162 }
163
164 export interface ITailorShop extends Omit<ITailorShopDatabase, "FavouriteLoadouts"> {
165 FavouriteLoadouts: IFavouriteLoadout[];
166 Colors: []; // ???
167 }