forked from OpenWF/SpaceNinjaServer
		
	feat: unequipping weapons & deleting loadout configs (#160)
This commit is contained in:
		
							parent
							
								
									477f678244
								
							
						
					
					
						commit
						9bded04dfd
					
				@ -19,7 +19,8 @@ const EquipmentSelectionSchema = new Schema<IEquipmentSelection>(
 | 
				
			|||||||
            default: { $oid: "000000000000000000000000" }
 | 
					            default: { $oid: "000000000000000000000000" }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        mod: Number,
 | 
					        mod: Number,
 | 
				
			||||||
        cus: Number
 | 
					        cus: Number,
 | 
				
			||||||
 | 
					        hide: Boolean
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        _id: false
 | 
					        _id: false
 | 
				
			||||||
 | 
				
			|||||||
@ -77,6 +77,11 @@ export const handleInventoryItemConfigChange = async (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    // all non-empty entries are one loadout slot
 | 
					                    // all non-empty entries are one loadout slot
 | 
				
			||||||
                    for (const [loadoutId, loadoutConfig] of Object.entries(newLoadout)) {
 | 
					                    for (const [loadoutId, loadoutConfig] of Object.entries(newLoadout)) {
 | 
				
			||||||
 | 
					                        if (loadoutConfig.Remove) {
 | 
				
			||||||
 | 
					                            loadout[loadoutSlot].pull({ _id: loadoutId });
 | 
				
			||||||
 | 
					                            continue;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        const oldLoadoutConfig = loadout[loadoutSlot].find(
 | 
					                        const oldLoadoutConfig = loadout[loadoutSlot].find(
 | 
				
			||||||
                            loadout => loadout._id.toString() === loadoutId
 | 
					                            loadout => loadout._id.toString() === loadoutId
 | 
				
			||||||
                        );
 | 
					                        );
 | 
				
			||||||
@ -106,8 +111,7 @@ export const handleInventoryItemConfigChange = async (
 | 
				
			|||||||
                            throw new Error("loadout index not found");
 | 
					                            throw new Error("loadout index not found");
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        //perhaps .overwrite() is better
 | 
					                        loadout[loadoutSlot][loadoutIndex].overwrite(loadoutConfig);
 | 
				
			||||||
                        loadout[loadoutSlot][loadoutIndex].set(loadoutConfig);
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                await loadout.save();
 | 
					                await loadout.save();
 | 
				
			||||||
 | 
				
			|||||||
@ -76,17 +76,19 @@ export interface ILoadoutConfigDatabase extends Omit<ILoadoutConfigClient, "Item
 | 
				
			|||||||
// for request and response from and to client
 | 
					// for request and response from and to client
 | 
				
			||||||
export interface ILoadoutConfigClient {
 | 
					export interface ILoadoutConfigClient {
 | 
				
			||||||
    ItemId: IOid;
 | 
					    ItemId: IOid;
 | 
				
			||||||
    n: string;
 | 
					    Remove?: boolean; // when client wants to remove a config, it only includes ItemId & Remove.
 | 
				
			||||||
    PresetIcon: string;
 | 
					    n?: string;
 | 
				
			||||||
    Favorite: boolean;
 | 
					    PresetIcon?: string;
 | 
				
			||||||
    s: IEquipmentSelection;
 | 
					    Favorite?: boolean;
 | 
				
			||||||
    p: IEquipmentSelection;
 | 
					    s?: IEquipmentSelection;
 | 
				
			||||||
    l: IEquipmentSelection;
 | 
					    p?: IEquipmentSelection;
 | 
				
			||||||
    m: IEquipmentSelection;
 | 
					    l?: IEquipmentSelection;
 | 
				
			||||||
 | 
					    m?: IEquipmentSelection;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IEquipmentSelection {
 | 
					export interface IEquipmentSelection {
 | 
				
			||||||
    ItemId: IOid;
 | 
					    ItemId?: IOid;
 | 
				
			||||||
    mod: number;
 | 
					    mod?: number;
 | 
				
			||||||
    cus: number;
 | 
					    cus?: number;
 | 
				
			||||||
 | 
					    hide?: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user