Add model fields and correct enum usage for vehicle class

pull/33/head
HardiReady 2018-04-14 13:44:50 +02:00
parent b927d48b86
commit 9d6c6e01b3
3 changed files with 35 additions and 6 deletions

View File

@ -25,6 +25,11 @@ const LogVehicleKillSchema = new Schema({
enum: ['BLUFOR', 'OPFOR', 'NONE'], enum: ['BLUFOR', 'OPFOR', 'NONE'],
required: true, required: true,
}, },
vehicleClass: {
type: String,
enum: ['LIGHT', 'HEAVY', 'AIR', "UNKNOWN"],
required: true,
},
}, { }, {
collection: 'logVehicle', collection: 'logVehicle',
}); });

View File

@ -24,7 +24,19 @@ const PlayerSchema = new Schema({
set: (v) => Math.round(v), set: (v) => Math.round(v),
required: true, required: true,
}, },
vehicle: { vehicleLight: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
required: true,
},
vehicleHeavy: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
required: true,
},
vehicleAir: {
type: Number, type: Number,
get: (v) => Math.round(v), get: (v) => Math.round(v),
set: (v) => Math.round(v), set: (v) => Math.round(v),

View File

@ -6,7 +6,7 @@ const WHITESPACE = ' ';
const VehicleClasses = Object.freeze({ const VehicleClasses = Object.freeze({
LIGHT: "Leicht", LIGHT: "Leicht",
HEAVY: "Leicht", HEAVY: "Schwer",
AIR: "Flug", AIR: "Flug",
UNKNOWN: "Unbekannt" UNKNOWN: "Unbekannt"
}); });
@ -74,6 +74,7 @@ const parseWarLog = (lineArray, war) => {
shooter: shooter ? shooter.name : null, shooter: shooter ? shooter.name : null,
target: target ? target.name : null, target: target ? target.name : null,
fraction: shooter ? shooter.fraction : 'NONE', fraction: shooter ? shooter.fraction : 'NONE',
vehicleClass: target.vehicleClass,
}); });
} }
} else { } else {
@ -262,18 +263,29 @@ const getVehicleAndFractionFromString = (nameClassFractionString) => {
const vehicleFraction = nameArray[nameArray.length - 1]; const vehicleFraction = nameArray[nameArray.length - 1];
nameArray.pop(); nameArray.pop();
const vehicleClass = nameArray[nameArray.length - 1].replace('(', '').replace(')', ''); const veheicleClassString = nameArray[nameArray.length - 1].replace('(', '').replace(')', '');
nameArray.pop(); nameArray.pop();
const vehicleName = nameArray.join(WHITESPACE); const vehicleName = nameArray.join(WHITESPACE);
// nno counting here - is some basic fraction equipment identifier (i.e. parachute) // skip logging here - this is some basic equipment identifier (i.e. parachute)
if (vehicleFraction === 'OPF_F' || vehicleFraction === 'BLU_F' || vehicleClass === VehicleClasses.UNKNOWN) { if (vehicleFraction === 'OPF_F' || vehicleFraction === 'BLU_F' || veheicleClassString === VehicleClasses.UNKNOWN) {
return; return;
} }
const fraction = vehicleFraction === '(OPT_NATO)' || vehicleFraction === '(OPT_NATO_T)' ? 'BLUFOR' : 'OPFOR'; const fraction = vehicleFraction === '(OPT_NATO)' || vehicleFraction === '(OPT_NATO_T)' ? 'BLUFOR' : 'OPFOR';
return {name: vehicleName, fraction: fraction, class: vehicleClass}; let vehicleClass;
for (const key in VehicleClasses) {
if (VehicleClasses.hasOwnProperty(key) && VehicleClasses[key] === veheicleClassString) {
vehicleClass = key;
}
}
return {
name: vehicleName,
fraction: fraction,
vehicleClass: vehicleClass,
};
}; };
const transformMoneyString = (budgetString) => { const transformMoneyString = (budgetString) => {