re factor rog

This commit is contained in:
2024-04-01 09:26:56 +05:30
parent dd36ab8399
commit edbf52825b
54 changed files with 2597 additions and 435 deletions

View File

@ -0,0 +1,98 @@
import 'package:flutter/material.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/features/data/checkpoint.dart';
import 'package:rogapp/features/data/user_location.dart';
enum GameStatus {
notStarted,
started,
inProgress,
atCheckpoint,
gameCompleted,
}
enum PendingAction {
none,
checkInPhoto,
receiptPhoto,
endGamePhoto,
}
@immutable
class GameState {
final GameStatus status;
final List<Feature> markers;
final UserLocation? currentLocation;
final Set<Feature> visitedMarkers;
final bool isWithinStartRadius;
final bool hasLeftStartArea;
final bool hasVisitedCheckpoint;
final Feature? currentCheckpoint;
final bool checkpointPhotoTaken;
final bool receiptPhotoTaken;
final PendingAction pendingAction;
const GameState({
this.status = GameStatus.notStarted,
this.markers = const [],
this.currentLocation,
this.visitedMarkers = const {},
this.isWithinStartRadius = false,
this.hasLeftStartArea = false,
this.hasVisitedCheckpoint = false,
this.currentCheckpoint,
this.checkpointPhotoTaken = false,
this.receiptPhotoTaken = false,
this.pendingAction = PendingAction.none,
});
LatLng? getUserLatLng() {
return currentLocation != null
? LatLng(currentLocation!.latitude, currentLocation!.longitude)
: null;
}
GameState.fromMap(Map<String, dynamic> map)
: status = GameStatus.values[map['status']],
markers =
List<Feature>.from(map['markers'].map((x) => Feature.fromMap(x))),
currentLocation = UserLocation.fromMap(map['currentLocation']),
visitedMarkers = Set<Feature>.from(
map['visitedMarkers'].map((x) => Feature.fromMap(x))),
isWithinStartRadius = map['isWithinStartRadius'],
hasLeftStartArea = map['hasLeftStartArea'],
hasVisitedCheckpoint = map['hasVisitedCheckpoint'],
currentCheckpoint = map['currentCheckpoint'] != null
? Feature.fromMap(map['currentCheckpoint'])
: null,
checkpointPhotoTaken = map['checkpointPhotoTaken'],
receiptPhotoTaken = map['receiptPhotoTaken'],
pendingAction = PendingAction.values[map['pendingAction']];
GameState copyWith({
GameStatus? status,
List<Feature>? markers,
UserLocation? currentLocation,
Set<Feature>? visitedMarkers,
bool? isWithinStartRadius,
bool? hasLeftStartArea,
bool? hasVisitedCheckpoint,
Feature? currentCheckpoint,
bool? checkpointPhotoTaken,
bool? receiptPhotoTaken,
PendingAction? pendingAction,
}) {
return GameState(
status: status ?? this.status,
markers: markers ?? this.markers,
currentLocation: currentLocation ?? this.currentLocation,
visitedMarkers: visitedMarkers ?? this.visitedMarkers,
isWithinStartRadius: isWithinStartRadius ?? this.isWithinStartRadius,
hasLeftStartArea: hasLeftStartArea ?? this.hasLeftStartArea,
hasVisitedCheckpoint: hasVisitedCheckpoint ?? this.hasVisitedCheckpoint,
currentCheckpoint: currentCheckpoint ?? this.currentCheckpoint,
checkpointPhotoTaken: checkpointPhotoTaken ?? this.checkpointPhotoTaken,
receiptPhotoTaken: receiptPhotoTaken ?? this.receiptPhotoTaken,
pendingAction: pendingAction ?? this.pendingAction);
}
}