feat(scum): add map trajectory projection
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"browser.local/platform/domain"
|
||||
"time"
|
||||
)
|
||||
|
||||
type GameMapTrajectoryPointResponse struct {
|
||||
MapX float64 `json:"mapX"`
|
||||
MapY float64 `json:"mapY"`
|
||||
OccurredAt time.Time `json:"occurredAt"`
|
||||
CollectedAt time.Time `json:"collectedAt"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
type GameMapTrajectoryEntityResponse struct {
|
||||
Kind string `json:"kind"`
|
||||
EntityID string `json:"entityId"`
|
||||
GamePlayerRecordID string `json:"gamePlayerRecordId,omitempty"`
|
||||
Label string `json:"label"`
|
||||
Points []GameMapTrajectoryPointResponse `json:"points"`
|
||||
CollectedAt time.Time `json:"collectedAt,omitempty"`
|
||||
Sources []string `json:"sources"`
|
||||
}
|
||||
type GameMapTrajectorySegmentResponse struct {
|
||||
GamePlayerRecordID string `json:"gamePlayerRecordId"`
|
||||
VehicleID string `json:"vehicleId"`
|
||||
StartedAt time.Time `json:"startedAt"`
|
||||
EndedAt time.Time `json:"endedAt,omitempty"`
|
||||
}
|
||||
type GameMapTrajectoryMapResponse struct {
|
||||
MapID string `json:"mapId"`
|
||||
MapVersion string `json:"mapVersion"`
|
||||
ImageWidth float64 `json:"imageWidth"`
|
||||
ImageHeight float64 `json:"imageHeight"`
|
||||
Precision float64 `json:"precision"`
|
||||
}
|
||||
type GameMapTrajectoryResponse struct {
|
||||
Status string `json:"status"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
Map *GameMapTrajectoryMapResponse `json:"map,omitempty"`
|
||||
From time.Time `json:"from,omitempty"`
|
||||
To time.Time `json:"to,omitempty"`
|
||||
Players []GameMapTrajectoryEntityResponse `json:"players"`
|
||||
Vehicles []GameMapTrajectoryEntityResponse `json:"vehicles"`
|
||||
RideSegments []GameMapTrajectorySegmentResponse `json:"rideSegments"`
|
||||
}
|
||||
|
||||
func GameMapTrajectoryFromDomain(value domain.GameMapTrajectoryView) GameMapTrajectoryResponse {
|
||||
value = domain.CopyGameMapTrajectoryView(value)
|
||||
response := GameMapTrajectoryResponse{Status: value.Status, Reason: value.Reason, From: value.From, To: value.To, Players: mapTrajectoryEntitiesFromDomain(value.Players), Vehicles: mapTrajectoryEntitiesFromDomain(value.Vehicles), RideSegments: make([]GameMapTrajectorySegmentResponse, len(value.RideSegments))}
|
||||
if value.Status != "missing-map" {
|
||||
response.Map = &GameMapTrajectoryMapResponse{MapID: value.Map.MapID, MapVersion: value.Map.MapVersion, ImageWidth: value.Map.ImageWidth, ImageHeight: value.Map.ImageHeight, Precision: value.Map.Precision}
|
||||
}
|
||||
for i, segment := range value.RideSegments {
|
||||
response.RideSegments[i] = GameMapTrajectorySegmentResponse{GamePlayerRecordID: segment.GamePlayerRecordID, VehicleID: segment.VehicleID, StartedAt: segment.StartedAt, EndedAt: segment.EndedAt}
|
||||
}
|
||||
return response
|
||||
}
|
||||
func mapTrajectoryEntitiesFromDomain(values []domain.GameMapTrajectoryEntity) []GameMapTrajectoryEntityResponse {
|
||||
result := make([]GameMapTrajectoryEntityResponse, len(values))
|
||||
for i, value := range values {
|
||||
points := make([]GameMapTrajectoryPointResponse, len(value.Points))
|
||||
for j, point := range value.Points {
|
||||
points[j] = GameMapTrajectoryPointResponse{MapX: point.MapX, MapY: point.MapY, OccurredAt: point.OccurredAt, CollectedAt: point.CollectedAt, Source: point.Source}
|
||||
}
|
||||
result[i] = GameMapTrajectoryEntityResponse{Kind: string(value.Kind), EntityID: value.EntityID, GamePlayerRecordID: value.GamePlayerRecordID, Label: value.Label, Points: points, CollectedAt: value.CollectedAt, Sources: domain.CopyStringSlice(value.Sources)}
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user