feat: implement setPlacedDecoInfo (#558)
This commit is contained in:
parent
abc3bd8624
commit
ba349535fb
12
src/controllers/api/setPlacedDecoInfoController.ts
Normal file
12
src/controllers/api/setPlacedDecoInfoController.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { ISetPlacedDecoInfoRequest } from "@/src/types/shipTypes";
|
||||
import { RequestHandler } from "express";
|
||||
import { handleSetPlacedDecoInfo } from "@/src/services/shipCustomizationsService";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
export const setPlacedDecoInfoController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const payload = JSON.parse(req.body as string) as ISetPlacedDecoInfoRequest;
|
||||
await handleSetPlacedDecoInfo(accountId, payload);
|
||||
res.end();
|
||||
};
|
@ -1,14 +1,34 @@
|
||||
import { toOid } from "@/src/helpers/inventoryHelpers";
|
||||
import { IOrbiter, IPersonalRooms, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
|
||||
import { IApartment, IGardening, IPlacedDecosDatabase } from "@/src/types/shipTypes";
|
||||
import { IApartment, IGardening, IPlacedDecosDatabase, IPictureFrameInfo } 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],
|
||||
Rot: [Number],
|
||||
Scale: Number
|
||||
Scale: Number,
|
||||
PictureFrameInfo: { type: pictureFrameInfoSchema, default: undefined }
|
||||
},
|
||||
{ id: false }
|
||||
);
|
||||
|
@ -51,6 +51,7 @@ import { sellController } from "@/src/controllers/api/sellController";
|
||||
import { setActiveQuestController } from "@/src/controllers/api/setActiveQuestController";
|
||||
import { setActiveShipController } from "@/src/controllers/api/setActiveShipController";
|
||||
import { setBootLocationController } from "@/src/controllers/api/setBootLocationController";
|
||||
import { setPlacedDecoInfoController } from "@/src/controllers/api/setPlacedDecoInfoController";
|
||||
import { setShipCustomizationsController } from "@/src/controllers/api/setShipCustomizationsController";
|
||||
import { setSupportedSyndicateController } from "@/src/controllers/api/setSupportedSyndicateController";
|
||||
import { setWeaponSkillTreeController } from "../controllers/api/setWeaponSkillTreeController";
|
||||
@ -128,6 +129,7 @@ apiRouter.post("/purchase.php", purchaseController);
|
||||
apiRouter.post("/rerollRandomMod.php", rerollRandomModController);
|
||||
apiRouter.post("/saveLoadout.php", saveLoadoutController);
|
||||
apiRouter.post("/sell.php", sellController);
|
||||
apiRouter.post("/setPlacedDecoInfo.php", setPlacedDecoInfoController);
|
||||
apiRouter.post("/setShipCustomizations.php", setShipCustomizationsController);
|
||||
apiRouter.post("/setWeaponSkillTree.php", setWeaponSkillTreeController);
|
||||
apiRouter.post("/shipDecorations.php", shipDecorationsController);
|
||||
|
@ -4,7 +4,8 @@ import {
|
||||
ISetShipCustomizationsRequest,
|
||||
IShipDatabase,
|
||||
IShipDecorationsRequest,
|
||||
IShipDecorationsResponse
|
||||
IShipDecorationsResponse,
|
||||
ISetPlacedDecoInfoRequest
|
||||
} from "@/src/types/shipTypes";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { Types } from "mongoose";
|
||||
@ -131,3 +132,23 @@ export const handleSetShipDecorations = async (
|
||||
|
||||
return { DecoId: decoId.toString(), Room: placedDecoration.Room, IsApartment: placedDecoration.IsApartment };
|
||||
};
|
||||
|
||||
export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlacedDecoInfoRequest): Promise<void> => {
|
||||
const personalRooms = await getPersonalRooms(accountId);
|
||||
|
||||
const room = personalRooms.Ship.Rooms.find(room => room.Name === req.Room);
|
||||
if (!room) {
|
||||
logger.error("room not found");
|
||||
throw new Error("room not found");
|
||||
}
|
||||
|
||||
const placedDeco = room.PlacedDecos?.find(x => x._id.toString() == req.DecoId);
|
||||
if (!placedDeco) {
|
||||
logger.error("deco not found");
|
||||
throw new Error("deco not found");
|
||||
}
|
||||
|
||||
placedDeco.PictureFrameInfo = req.PictureFrameInfo;
|
||||
|
||||
await personalRooms.save();
|
||||
};
|
||||
|
@ -70,6 +70,7 @@ export interface IPlacedDecosDatabase {
|
||||
Pos: [number, number, number];
|
||||
Rot: [number, number, number];
|
||||
Scale: number;
|
||||
PictureFrameInfo?: IPictureFrameInfo;
|
||||
_id: Types.ObjectId;
|
||||
}
|
||||
|
||||
@ -115,3 +116,27 @@ export interface IShipDecorationsResponse {
|
||||
OldRoom?: string;
|
||||
NewRoom?: string;
|
||||
}
|
||||
|
||||
export interface ISetPlacedDecoInfoRequest {
|
||||
DecoType: string;
|
||||
DecoId: string;
|
||||
Room: string;
|
||||
PictureFrameInfo: IPictureFrameInfo;
|
||||
BootLocation: string;
|
||||
}
|
||||
|
||||
export interface 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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user