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

XFESpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/XFESpaceNinjaServer

feat: getShip import (#2627)

Re #2592 Unsure about import note, is it okay that we leave the API path? Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2627 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>

b0b68f47
AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
提交于

代码差异

11 个文件 +101 -13
Modified src/controllers/custom/importController.ts +11 -3
@@ -1,8 +1,10 @@
1 import { importInventory, importLoadOutPresets } from "@/src/services/importService";
1 import { importInventory, importLoadOutPresets, importPersonalRooms } from "@/src/services/importService";
2 2 import { getInventory } from "@/src/services/inventoryService";
3 3 import { getLoadout } from "@/src/services/loadoutService";
4 4 import { getAccountIdForRequest } from "@/src/services/loginService";
5 import { getPersonalRooms } from "@/src/services/personalRoomsService";
5 6 import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
7 import { IGetShipResponse } from "@/src/types/personalRoomsTypes";
6 8 import { RequestHandler } from "express";
7 9
8 10 export const importController: RequestHandler = async (req, res) => {
@@ -13,15 +15,21 @@ export const importController: RequestHandler = async (req, res) => {
13 15 importInventory(inventory, request.inventory);
14 16 await inventory.save();
15 17
16 if (request.inventory.LoadOutPresets) {
18 if ("LoadOutPresets" in request.inventory && request.inventory.LoadOutPresets) {
17 19 const loadout = await getLoadout(accountId);
18 20 importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
19 21 await loadout.save();
20 22 }
21 23
24 if ("Ship" in request.inventory || "Apartment" in request.inventory || "TailorShop" in request.inventory) {
25 const personalRooms = await getPersonalRooms(accountId);
26 importPersonalRooms(personalRooms, request.inventory);
27 await personalRooms.save();
28 }
29
22 30 res.end();
23 31 };
24 32
25 33 interface IImportRequest {
26 inventory: Partial<IInventoryClient>;
34 inventory: Partial<IInventoryClient> | Partial<IGetShipResponse>;
27 35 }
Modified src/services/importService.ts +70 -0
@@ -44,6 +44,22 @@ import {
44 44 IKubrowPetDetailsClient,
45 45 IKubrowPetDetailsDatabase
46 46 } from "@/src/types/equipmentTypes";
47 import {
48 IApartmentClient,
49 IApartmentDatabase,
50 IFavouriteLoadout,
51 IFavouriteLoadoutDatabase,
52 IGetShipResponse,
53 IOrbiterClient,
54 IOrbiterDatabase,
55 IPersonalRoomsDatabase,
56 IPlantClient,
57 IPlantDatabase,
58 IPlanterClient,
59 IPlanterDatabase,
60 ITailorShop,
61 ITailorShopDatabase
62 } from "@/src/types/personalRoomsTypes";
47 63
48 64 const convertDate = (value: IMongoDate): Date => {
49 65 return new Date(parseInt(value.$date.$numberLong));
@@ -429,3 +445,57 @@ export const importLoadOutPresets = (db: ILoadoutDatabase, client: ILoadOutPrese
429 445 db.OPERATOR_ADULT = client.OPERATOR_ADULT.map(convertLoadOutConfig);
430 446 db.DRIFTER = client.DRIFTER.map(convertLoadOutConfig);
431 447 };
448
449 const convertShip = (client: IOrbiterClient): IOrbiterDatabase => {
450 return {
451 ...client,
452 ShipInterior: {
453 ...client.ShipInterior,
454 Colors: Array.isArray(client.ShipInterior.Colors) ? {} : client.ShipInterior.Colors
455 },
456 FavouriteLoadoutId: client.FavouriteLoadoutId ? new Types.ObjectId(client.FavouriteLoadoutId.$oid) : undefined
457 };
458 };
459
460 const convertPlant = (client: IPlantClient): IPlantDatabase => {
461 return {
462 ...client,
463 EndTime: convertDate(client.EndTime)
464 };
465 };
466
467 const convertPlanter = (client: IPlanterClient): IPlanterDatabase => {
468 return {
469 ...client,
470 Plants: client.Plants.map(convertPlant)
471 };
472 };
473
474 const convertFavouriteLoadout = (client: IFavouriteLoadout): IFavouriteLoadoutDatabase => {
475 return {
476 ...client,
477 LoadoutId: new Types.ObjectId(client.LoadoutId.$oid)
478 };
479 };
480
481 const convertApartment = (client: IApartmentClient): IApartmentDatabase => {
482 return {
483 ...client,
484 Gardening: { Planters: client.Gardening.Planters.map(convertPlanter) },
485 FavouriteLoadouts: client.FavouriteLoadouts ? client.FavouriteLoadouts.map(convertFavouriteLoadout) : []
486 };
487 };
488
489 const convertTailorShop = (client: ITailorShop): ITailorShopDatabase => {
490 return {
491 ...client,
492 Colors: Array.isArray(client.Colors) ? {} : client.Colors,
493 FavouriteLoadouts: client.FavouriteLoadouts ? client.FavouriteLoadouts.map(convertFavouriteLoadout) : []
494 };
495 };
496
497 export const importPersonalRooms = (db: IPersonalRoomsDatabase, client: Partial<IGetShipResponse>): void => {
498 if (client.Ship !== undefined) db.Ship = convertShip(client.Ship);
499 if (client.Apartment !== undefined) db.Apartment = convertApartment(client.Apartment);
500 if (client.TailorShop !== undefined) db.TailorShop = convertTailorShop(client.TailorShop);
501 };
Modified src/types/personalRoomsTypes.ts +2 -2
@@ -90,7 +90,7 @@ export interface IGardeningDatabase {
90 90 export interface IApartmentClient {
91 91 Gardening: IGardeningClient;
92 92 Rooms: IRoom[];
93 FavouriteLoadouts: IFavouriteLoadout[];
93 FavouriteLoadouts?: IFavouriteLoadout[];
94 94 VideoWallBackdrop?: string;
95 95 Soundscape?: string;
96 96 }
@@ -210,7 +210,7 @@ export interface ITailorShopDatabase {
210 210 }
211 211
212 212 export interface ITailorShop extends Omit<ITailorShopDatabase, "FavouriteLoadouts"> {
213 FavouriteLoadouts: IFavouriteLoadout[];
213 FavouriteLoadouts?: IFavouriteLoadout[];
214 214 }
215 215
216 216 export type RoomsType = { Name: string; MaxCapacity: number; PlacedDecos: Types.DocumentArray<IPlacedDecosDatabase> };
Modified static/webui/index.html +4 -1
@@ -1147,7 +1147,10 @@
1147 1147 </div>
1148 1148 </div>
1149 1149 <div data-route="/webui/import" data-title="Import | OpenWF WebUI">
1150 <p data-loc="import_importNote"></p>
1150 <p>
1151 <span data-loc="import_importNote"></span>
1152 <span data-loc="import_importNote2"></span>
1153 </p>
1151 1154 <textarea class="form-control" id="import-inventory" style="height: calc(100vh - 300px)"></textarea>
1152 1155 <button class="btn btn-primary mt-3" onclick="doImport();" data-loc="import_submit"></button>
1153 1156 <p class="mt-3 mb-1" data-loc="import_samples"></p>
Modified static/webui/translations/de.js +2 -1
@@ -307,7 +307,8 @@ dict = {
307 307 worldState_varziaFullyStocked: `Varzia hat volles Inventar`,
308 308 worldState_varziaOverride: `Varzia-Angebotsüberschreibung`,
309 309
310 import_importNote: `Du kannst hier eine vollständige oder teilweise Inventarantwort (Client-Darstellung) einfügen. Alle Felder, die vom Importer unterstützt werden, <b>werden in deinem Account überschrieben</b>.`,
310 import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
311 import_importNote2: `Alle Felder, die vom Importer unterstützt werden, <b>werden in deinem Account überschrieben</b>.`,
311 312 import_submit: `Absenden`,
312 313 import_samples: `Beispiele:`,
313 314 import_samples_maxFocus: `Alle Fokus-Schulen maximiert`,
Modified static/webui/translations/en.js +2 -1
@@ -306,7 +306,8 @@ dict = {
306 306 worldState_varziaFullyStocked: `Varzia Fully Stocked`,
307 307 worldState_varziaOverride: `Varzia Rotation Override`,
308 308
309 import_importNote: `You can provide a full or partial inventory response (client respresentation) here. All fields that are supported by the importer <b>will be overwritten</b> in your account.`,
309 import_importNote: `You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
310 import_importNote2: `All fields that are supported by the importer <b>will be overwritten</b> in your account.`,
310 311 import_submit: `Submit`,
311 312 import_samples: `Samples:`,
312 313 import_samples_maxFocus: `All Focus Schools Maxed Out`,
Modified static/webui/translations/es.js +2 -1
@@ -307,7 +307,8 @@ dict = {
307 307 worldState_varziaFullyStocked: `Varzia con stock completo`,
308 308 worldState_varziaOverride: `Cambio en rotación de Varzia`,
309 309
310 import_importNote: `Puedes proporcionar una respuesta de inventario completa o parcial (representación del cliente) aquí. Todos los campos compatibles con el importador <b>serán sobrescritos</b> en tu cuenta.`,
310 import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
311 import_importNote2: `Todos los campos compatibles con el importador <b>serán sobrescritos</b> en tu cuenta.`,
311 312 import_submit: `Enviar`,
312 313 import_samples: `Muestras:`,
313 314 import_samples_maxFocus: `Todas las escuelas de enfoque al máximo`,
Modified static/webui/translations/fr.js +2 -1
@@ -307,7 +307,8 @@ dict = {
307 307 worldState_varziaFullyStocked: `Stock de Varzia au max`,
308 308 worldState_varziaOverride: `Rotation de Varzia`,
309 309
310 import_importNote: `Import manuel. Toutes les modifcations supportées par l'inventaire <b>écraseront celles présentes dans la base de données</b>.`,
310 import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
311 import_importNote2: `[UNTRANSLATED] All fields that are supported by the importer <b>will be overwritten</b> in your account.`,
311 312 import_submit: `Soumettre`,
312 313 import_samples: `Échantillons :`,
313 314 import_samples_maxFocus: `Toutes les écoles de focus au rang max`,
Modified static/webui/translations/ru.js +2 -1
@@ -307,7 +307,8 @@ dict = {
307 307 worldState_varziaFullyStocked: `Полный ассортимент Варзии`,
308 308 worldState_varziaOverride: `Изменение ротации Варзии`,
309 309
310 import_importNote: `Вы можете загрузить полный или частичный ответ инвентаря (клиентское представление) здесь. Все поддерживаемые поля <b>будут перезаписаны</b> в вашем аккаунте.`,
310 import_importNote: `Вы можете загрузить полный или частичный ответ <code>inventory.php</code> или <code>getShip.php</code> (клиентское представление) здесь. `,
311 import_importNote2: `Все поддерживаемые поля <b>будут перезаписаны</b> в вашем аккаунте.`,
311 312 import_submit: `Отправить`,
312 313 import_samples: `Пример:`,
313 314 import_samples_maxFocus: `Все школы Фокуса макс. уровня`,
Modified static/webui/translations/uk.js +2 -1
@@ -307,7 +307,8 @@ dict = {
307 307 worldState_varziaFullyStocked: `Повний асортимент Варзії`,
308 308 worldState_varziaOverride: `Зміна ротації Варзії`,
309 309
310 import_importNote: `Ви можете завантажити повну або часткову відповідь спорядження (клієнтське представлення) тут. Всі підтримувані поля <b>будуть перезаписані</b> у вашому акаунті.`,
310 import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
311 import_importNote2: `Всі підтримувані поля <b>будуть перезаписані</b> у вашому акаунті.`,
311 312 import_submit: `Відправити`,
312 313 import_samples: `Приклад:`,
313 314 import_samples_maxFocus: `Всі школи Фокусу макс. рівня`,
Modified static/webui/translations/zh.js +2 -1
@@ -307,7 +307,8 @@ dict = {
307 307 worldState_varziaFullyStocked: `瓦奇娅开启全部库存商品`,
308 308 worldState_varziaOverride: `瓦奇娅(Prime重生)轮换状态`,
309 309
310 import_importNote: `您可以在此处提供完整或部分库存响应(客户端表示)。支持的所有字段<b>将被覆盖</b>到您的账户中。`,
310 import_importNote: `[UNTRANSLATED] You can provide a full or partial <code>inventory.php</code> or <code>getShip.php</code> response (client representation) here.`,
311 import_importNote2: `支持的所有字段<b>将被覆盖</b>到您的账户中。`,
311 312 import_submit: `提交`,
312 313 import_samples: `示例:`,
313 314 import_samples_maxFocus: `所有专精学派完全精通`,