From 669e844b75dc72d34975f690bd0ac6203f32a6ba Mon Sep 17 00:00:00 2001 From: daveajlee Date: Mon, 4 Sep 2023 22:01:54 +0200 Subject: [PATCH] Add vehicle depot functionality to desktop client without search for fleet number and selling vehicles --- desktop/src/app/game/game.model.ts | 11 +++ .../src/app/messages/messages.component.html | 4 + .../src/app/messages/messages.component.ts | 7 +- .../scenariolist/scenariolist.component.ts | 16 ++++ .../src/app/vehicles/suppliedvehicle.model.ts | 6 +- .../vehicle-detail.component.html | 89 ++++++------------- .../vehicle-detail.component.ts | 14 ++- .../src/app/vehicles/vehiclemodel.model.ts | 26 ++++++ .../src/app/vehicles/vehicles.component.html | 16 ++-- .../src/app/vehicles/vehicles.component.ts | 23 +++-- desktop/src/data/scenarios/landuff.data.ts | 3 +- desktop/src/data/scenarios/longts.data.ts | 3 +- desktop/src/data/scenarios/mdorf.data.ts | 3 +- 13 files changed, 138 insertions(+), 83 deletions(-) create mode 100644 desktop/src/app/vehicles/vehiclemodel.model.ts diff --git a/desktop/src/app/game/game.model.ts b/desktop/src/app/game/game.model.ts index 15a9d76..1bd69d8 100644 --- a/desktop/src/app/game/game.model.ts +++ b/desktop/src/app/game/game.model.ts @@ -1,6 +1,7 @@ import {Scenario} from "../shared/scenario.model"; import {Route} from "../routes/route.model"; import {Message} from "../messages/message.model"; +import {Vehicle} from "../vehicles/vehicle.model"; /** * This class defines a model for the game that is currently loaded in the TraMS application. @@ -15,6 +16,7 @@ export class Game { public difficultyLevel: string; public routes: Route[]; public messages: Message[]; + public vehicles: Vehicle[]; /** * Construct a new game which contains the supplied data. @@ -35,6 +37,7 @@ export class Game { this.difficultyLevel = difficultyLevel; this.routes = []; this.messages = []; + this.vehicles = []; } /** @@ -45,6 +48,14 @@ export class Game { this.routes.push(route); } + /** + * This method adds a vehicle to the vehicles array if we are currently saving routes locally. + * @param vehicle a vehicle object with the vehicle information to add to the vehicles array. + */ + addVehicle(vehicle: Vehicle): void { + this.vehicles.push(vehicle); + } + /** * This method adds a message to the messages array if we are currently saving messages locally. * @param subject the subject of the message to add. diff --git a/desktop/src/app/messages/messages.component.html b/desktop/src/app/messages/messages.component.html index 81a429d..c19d549 100644 --- a/desktop/src/app/messages/messages.component.html +++ b/desktop/src/app/messages/messages.component.html @@ -31,3 +31,7 @@

{{message.subject}}

+ +
+ +
diff --git a/desktop/src/app/messages/messages.component.ts b/desktop/src/app/messages/messages.component.ts index 7200986..3f1302d 100644 --- a/desktop/src/app/messages/messages.component.ts +++ b/desktop/src/app/messages/messages.component.ts @@ -5,6 +5,7 @@ import { faShareFromSquare } from '@fortawesome/free-solid-svg-icons'; import { faTrash } from '@fortawesome/free-solid-svg-icons'; import {Message} from "./message.model"; import {GameService} from "../shared/game.service"; +import {Router} from "@angular/router"; @Component({ selector: 'app-messages', @@ -19,7 +20,7 @@ export class MessagesComponent { displayMessages: Message[]; gameService: GameService; - constructor(private gameService2: GameService) { + constructor(private gameService2: GameService, public router: Router) { this.displayMessages = []; this.gameService = gameService2; this.onInboxSelect(); @@ -56,4 +57,8 @@ export class MessagesComponent { checkForTrash(message) { return message.folder.valueOf() === "TRASH"; } + + backToManagementScreen(): void { + this.router.navigate(['management']); + } } diff --git a/desktop/src/app/scenariolist/scenariolist.component.ts b/desktop/src/app/scenariolist/scenariolist.component.ts index c72f8b2..5925c06 100644 --- a/desktop/src/app/scenariolist/scenariolist.component.ts +++ b/desktop/src/app/scenariolist/scenariolist.component.ts @@ -8,6 +8,7 @@ import { SCENARIOS } from 'src/data/scenario.data'; import {SCENARIO_LANDUFF} from "../../data/scenarios/landuff.data"; import {SCENARIO_LONGTS} from "../../data/scenarios/longts.data"; import {SCENARIO_MDORF} from "../../data/scenarios/mdorf.data"; +import {Vehicle} from "../vehicles/vehicle.model"; @Component({ selector: 'app-scenariolist', @@ -57,12 +58,27 @@ export class ScenariolistComponent implements OnInit { */ onScenarioSelect(scenario: string): void { this.gameService.setGame(new Game(this.company, this.playerName, this.startingDate, this.loadScenario(scenario), this.difficultyLevel,)); + // Add the message. this.gameService.getGame().addMessage("New Managing Director Announced", "Congratulations - " + this.playerName + " has been appointed Managing Director of " + this.company + "!" + "\n\nYour targets for the coming days and months: \n" + this.formatTargets(this.loadScenario(scenario).targets) + "\nYour contract to run public transport services in " + scenario + " will be terminated if these targets are not met!" + "\n\nGood luck!", "INBOX"); + // Add the supplied vehicles. + var mySuppliedVehicles = this.loadScenario(scenario).suppliedVehicles; + for ( var i = 0; i < mySuppliedVehicles.length; i++ ) { + for ( var j = 0; j < mySuppliedVehicles[i].quantity; j++ ) { + const additionalProps = new Map(); + additionalProps.set('Model', mySuppliedVehicles[i].model.modelName); + additionalProps.set('Age', '0 months'); + additionalProps.set('Standing Capacity', '' + mySuppliedVehicles[i].model.standingCapacity); + additionalProps.set('Seating Capacity', '' + mySuppliedVehicles[i].model.seatingCapacity); + additionalProps.set('Value', '' + mySuppliedVehicles[i].model.value); + this.gameService.getGame().addVehicle(new Vehicle('' + (i+j+1), mySuppliedVehicles[i].vehicleType, '', + '', '', 0, additionalProps)); + } + } this.router.navigate(['management']); // this.scenarioService.createCompany(this.company, this.playerName, this.difficultyLevel, this.startingDate, scenario); } diff --git a/desktop/src/app/vehicles/suppliedvehicle.model.ts b/desktop/src/app/vehicles/suppliedvehicle.model.ts index 4c1d6e7..2e30ee7 100644 --- a/desktop/src/app/vehicles/suppliedvehicle.model.ts +++ b/desktop/src/app/vehicles/suppliedvehicle.model.ts @@ -1,10 +1,12 @@ +import {VehicleModel} from "./vehiclemodel.model"; + /** * This class defines a model for Vehicles which can be supplied as part of a scenario. */ export class SuppliedVehicles { public vehicleType: string; - public model: string; + public model: VehicleModel; public quantity: number; /** @@ -13,7 +15,7 @@ export class SuppliedVehicles { * @param model the model of the supplied vehicle * @param quantity the quantity/amount of this model and type that are supplied */ - constructor( vehicleType: string, model: string, quantity: number) { + constructor( vehicleType: string, model: VehicleModel, quantity: number) { this.vehicleType = vehicleType; this.model = model; this.quantity = quantity; diff --git a/desktop/src/app/vehicles/vehicle-detail/vehicle-detail.component.html b/desktop/src/app/vehicles/vehicle-detail/vehicle-detail.component.html index 2fa72b7..c57a0bd 100644 --- a/desktop/src/app/vehicles/vehicle-detail/vehicle-detail.component.html +++ b/desktop/src/app/vehicles/vehicle-detail/vehicle-detail.component.html @@ -1,71 +1,32 @@ - -Vehicle Picture +

-
+
-
- -
-

Fleet Number:

-
-
-

{{vehicle.fleetNumber}}

-
-
- -
-
-

Type:

-
-
-

{{vehicle.vehicleType}}

-
-
- -
-
-

Livery:

-
-
-

{{vehicle.livery}}

-
-
- -
-
-

Allocation:

-
-
-

{{vehicle.allocatedTour}}

-
-
- -
-
-

{{recipient.key}}:

-
-
-

{{recipient.value}}

-
+
+ + Vehicle Picture
- -
-
-

Inspection Status:

-
-
-

{{vehicle.inspectionStatus}}

-
-
- -
-
-

Days until next inspection:

-
-
-

{{vehicle.nextInspectionDueInDays}}

-
+
+ +

Fleet Number: {{vehicle.fleetNumber}}

+ +

Type: {{vehicle.vehicleType}}

+ +

Livery: {{vehicle.livery}}

+ +

Allocation: {{vehicle.allocatedTour ? vehicle.allocatedTour : 'Not Assigned'}}

+ +
+

{{recipient.key}}: {{recipient.value}}

+
+ +

Inspection Status: {{vehicle.inspectionStatus}}

+ +

Days until next inspection: {{vehicle.nextInspectionDueInDays}}

+
+
+
\ No newline at end of file diff --git a/desktop/src/app/vehicles/vehicle-detail/vehicle-detail.component.ts b/desktop/src/app/vehicles/vehicle-detail/vehicle-detail.component.ts index 7b7a08c..91fb62c 100644 --- a/desktop/src/app/vehicles/vehicle-detail/vehicle-detail.component.ts +++ b/desktop/src/app/vehicles/vehicle-detail/vehicle-detail.component.ts @@ -4,6 +4,7 @@ import {Subscription} from 'rxjs'; import {VehiclesService} from '../vehicles.service'; import {ActivatedRoute, Params} from '@angular/router'; import {Vehicle} from '../vehicle.model'; +import {GameService} from "../../shared/game.service"; @Component({ selector: 'app-vehicle-detail', @@ -23,18 +24,22 @@ export class VehicleDetailComponent implements OnInit, OnDestroy { /** * Construct a new vehicle-detail component based on the supplied information. * @param vehiclesService a service which can retrieve and format vehicle information + * @param gameService a service which can retrieve game information * @param route a variable which contains the current vehicle that the user clicked on. */ - constructor(private vehiclesService: VehiclesService, private route: ActivatedRoute) { } + constructor(private vehiclesService: VehiclesService, private route: ActivatedRoute, private gameService: GameService) { } /** * Initialise the vehicle information during construction and ensure all variables are set to the correct data. */ ngOnInit(): void { - // Save the stop information based on the id. this.idSubscription = this.route.params.subscribe((params: Params) => { this.id = +params['id']; - this.vehicle = this.vehiclesService.getVehicle(this.id); + if ( this.gameService.getGame().vehicles.length > 0 ) { + this.vehicle = this.gameService.getGame().vehicles[this.id]; + } else { + this.vehicle = this.vehiclesService.getVehicle(this.id); + } }); } @@ -52,6 +57,9 @@ export class VehicleDetailComponent implements OnInit, OnDestroy { return this.vehicle.vehicleType; } + sellVehicle(vehicle: Vehicle): void { + console.log('It is currently not possible to sell vehicles for vehicle ' + vehicle.fleetNumber); + } /*verifyMap(): void { this.vehicle.additionalTypeInformationMap.forEach().forEach((key: string, value: string) => { console.log(key, value); diff --git a/desktop/src/app/vehicles/vehiclemodel.model.ts b/desktop/src/app/vehicles/vehiclemodel.model.ts new file mode 100644 index 0000000..33d1a2a --- /dev/null +++ b/desktop/src/app/vehicles/vehiclemodel.model.ts @@ -0,0 +1,26 @@ +/** + * This class defines a model for Vehicle Models in TraMS which consist of things like seating capacity, + * standing capacity etc. + */ +export class VehicleModel { + + public modelName: string; + public seatingCapacity: number; + public standingCapacity: number; + public value: number; + + /** + * Construct a new VehicleModel object with the supplied data. + * @param modelName the name of the model + * @param seatingCapacity the seating capacity of this model + * @param standingCapacity the standing capacity of this model + * @param value the current selling price of this model. + */ + constructor ( modelName: string, seatingCapacity: number, standingCapacity: number, value: number ) { + this.modelName = modelName; + this.seatingCapacity = seatingCapacity; + this.standingCapacity = standingCapacity; + this.value = value; + } + +} \ No newline at end of file diff --git a/desktop/src/app/vehicles/vehicles.component.html b/desktop/src/app/vehicles/vehicles.component.html index 9892f9f..9b4967d 100644 --- a/desktop/src/app/vehicles/vehicles.component.html +++ b/desktop/src/app/vehicles/vehicles.component.html @@ -1,19 +1,22 @@ + + +
-

Vehicles

+

Vehicles


-

Vehicles ensure that your customers can travel from A to B. Therefore you should aim to have as many vehicles as possible to ensure reliable services. But don't forget if a vehicle is not in use then you are making a loss on this vehicle!

+

Vehicles ensure that your customers can travel from A to B. Therefore you should aim to have as many vehicles as possible to ensure reliable services. But don't forget if a vehicle is not in use then you are making a loss on this vehicle!


-

Click on a vehicle to access more information about the vehicle.

+

Click on a vehicle to access more information about the vehicle.

-
+

- +

@@ -36,3 +39,6 @@

Vehicles

+
+ +
\ No newline at end of file diff --git a/desktop/src/app/vehicles/vehicles.component.ts b/desktop/src/app/vehicles/vehicles.component.ts index 840361e..32cf323 100644 --- a/desktop/src/app/vehicles/vehicles.component.ts +++ b/desktop/src/app/vehicles/vehicles.component.ts @@ -5,6 +5,8 @@ import {VehiclesService} from './vehicles.service'; import {DataService} from '../shared/data.service'; import {HttpClient} from '@angular/common/http'; import {VehiclesResponse} from './vehicles-response.model'; +import {GameService} from "../shared/game.service"; +import {Router} from "@angular/router"; @Component({ selector: 'app-vehicles', @@ -26,16 +28,23 @@ export class VehiclesComponent implements OnInit, OnDestroy { * @param http an http client which can make http calls * @param dataService which contains the HTTP connection to the server * @param vehiclesService which formats the HTTP calls into a way which the frontend can read and render. + * @param gameService a service which retrieves game information + * @param router a router service provided by Angular */ - constructor(private http: HttpClient, private dataService: DataService, private vehiclesService: VehiclesService ) { } + constructor(private http: HttpClient, private dataService: DataService, private vehiclesService: VehiclesService, + private gameService: GameService, private router:Router) { } /** - * Initialise a new stops component which maintains a list of stops that can be updated and set from the server calls. + * Initialise a new vheicles component which maintains a list of vehicles that can be updated and set from the server calls. */ ngOnInit(): void { - this.subscription = this.vehiclesService.vehiclesChanged.subscribe((vehicles: Vehicle[]) => { - this.vehicles = vehicles; - }); + if ( this.gameService.getGame().vehicles.length > 0 ) { + this.vehicles = this.gameService.getGame().vehicles; + } else { + this.subscription = this.vehiclesService.vehiclesChanged.subscribe((vehicles: Vehicle[]) => { + this.vehicles = vehicles; + }); + } } searchByFleetNumber(searchValue: string): void { @@ -53,4 +62,8 @@ export class VehiclesComponent implements OnInit, OnDestroy { this.searchSubscription.unsubscribe(); } + backToManagementScreen(): void { + this.router.navigate(['management']); + } + } diff --git a/desktop/src/data/scenarios/landuff.data.ts b/desktop/src/data/scenarios/landuff.data.ts index 51c6f7e..b63f6f8 100644 --- a/desktop/src/data/scenarios/landuff.data.ts +++ b/desktop/src/data/scenarios/landuff.data.ts @@ -1,5 +1,6 @@ import { Scenario } from "src/app/shared/scenario.model"; import {SuppliedVehicles} from "../../app/vehicles/suppliedvehicle.model"; +import {VehicleModel} from "../../app/vehicles/vehiclemodel.model"; // Map of the scenario. const MAP = "landuff-map-picture.jpg"; @@ -17,7 +18,7 @@ const TARGETS = ["Serve all bus stops in Landuff.", "Ensure a frequent service o const MINIMUM_SATISFACTION= 70; // The type and number of supplied vehicles. -const SUPPLIED_VEHICLES = [new SuppliedVehicles("Bus", "MyBus Single Decker", 4)]; +const SUPPLIED_VEHICLES = [new SuppliedVehicles("Bus", new VehicleModel("MyBus Single Decker", 44, 36, 85000.0), 4)]; // The supplied drivers for this scenario. const SUPPLIED_DRIVERS = ["Max Mustermann","Robert Mustermann","Daniela Mustermann","Daniel Mustermann"]; diff --git a/desktop/src/data/scenarios/longts.data.ts b/desktop/src/data/scenarios/longts.data.ts index 3c9fde0..5dd8977 100644 --- a/desktop/src/data/scenarios/longts.data.ts +++ b/desktop/src/data/scenarios/longts.data.ts @@ -1,5 +1,6 @@ import {Scenario} from "../../app/shared/scenario.model"; import {SuppliedVehicles} from "../../app/vehicles/suppliedvehicle.model"; +import {VehicleModel} from "../../app/vehicles/vehiclemodel.model"; // Map of the scenario. const MAP = "longtscity-map-picture.jpg"; @@ -17,7 +18,7 @@ const TARGETS = ["Serve all bus stops in Longts.", "Ensure a very frequent servi const MINIMUM_SATISFACTION= 50; // The type and number of supplied vehicles. -const SUPPLIED_VEHICLES = [new SuppliedVehicles("Bus", "MyBus Single Decker", 2)]; +const SUPPLIED_VEHICLES = [new SuppliedVehicles("Bus", new VehicleModel("MyBus Single Decker", 44, 36, 85000.0), 2)]; // The supplied drivers for this scenario. const SUPPLIED_DRIVERS = ["Max Mustermann","Robert Mustermann"]; diff --git a/desktop/src/data/scenarios/mdorf.data.ts b/desktop/src/data/scenarios/mdorf.data.ts index c15b218..6ab6b54 100644 --- a/desktop/src/data/scenarios/mdorf.data.ts +++ b/desktop/src/data/scenarios/mdorf.data.ts @@ -1,5 +1,6 @@ import {Scenario} from "../../app/shared/scenario.model"; import {SuppliedVehicles} from "../../app/vehicles/suppliedvehicle.model"; +import {VehicleModel} from "../../app/vehicles/vehiclemodel.model"; // Map of the scenario. const MAP = "mdorf-map-picture.jpg"; @@ -17,7 +18,7 @@ const TARGETS = ["Serve all bus stops in MDorf.", "Ensure a frequent service on const MINIMUM_SATISFACTION= 35; // The type and number of supplied vehicles. -const SUPPLIED_VEHICLES = [new SuppliedVehicles("Bus", "MyBus Single Decker", 3)]; +const SUPPLIED_VEHICLES = [new SuppliedVehicles("Bus", new VehicleModel("MyBus Single Decker", 44, 36, 85000.0), 3)]; // The supplied drivers for this scenario. const SUPPLIED_DRIVERS = ["Max Mustermann","Robert Mustermann","Daniela Mustermann"];