| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import 'package:app_business/service/api.dart';
- import 'package:track_common/model.dart';
- import 'package:track_common/service/map_watch.dart';
- import '../generated/base.pb.dart' as pb;
- import '../model/game_map.dart';
- class MapWatchImpl extends MapWatch {
- MapWatchImpl({required super.id});
- ApiService get _api => Get.find();
- @override
- Future<List<EventOnMap>> getEventList(int mapId) async {
- final r = await _api.stub
- .toUserDetailQueryV2(pb.ToUserDetailQueryRequestV2()..mapId = mapId);
- final eventList = <EventOnMap>[];
- for (var one in r.list) {
- eventList.add(EventOnMap()
- ..info.id = one.actId
- ..userList = one.userList.map((e) => toAppPlayer(e)).toList());
- }
- return eventList;
- }
- PlayerOnMap toAppPlayer(pb.ToOrienteerInGameInfo e) {
- final save = e.gameSaveInfo;
- final startAt = save.hasStartAt() ? save.startAt.toModel() : DateTime.now();
- return PlayerOnMap()
- ..info.id = e.userId
- ..startAt = startAt
- ..duration = DateTime.now().difference(startAt)
- ..distance = e.gpsInfo.distance.meter
- ..cpListChecked = save.checkedSortedList.isEmpty
- ? []
- : save.checkedSortedList
- .map((e) => ControlPoint()
- ..isSuccess = e.isCheckSuccess
- ..intId = e.controlPointId.toInt64())
- .toList();
- }
- @override
- Future<EventInfo> getEventInfo(int id) async {
- final r = await _api.stub.toActionBasicQuery(IdRequest()..id = Int64(id));
- final event = EventInfo()
- ..name = r.actName
- ..cpAllCount = r.totalControlNum;
- return event;
- }
- @override
- Future<PlayerInfo> getPlayerInfo(int eventId, int userId) async {
- final r = await _api.stub
- .toUserInActionBasicQuery(pb.ToUserInActionBasicQueryRequest()
- ..actId = eventId
- ..userId = userId);
- final player = PlayerInfo()
- ..id = r.userId
- ..name = r.baseInfo.name
- ..routeName = r.courseBaseInfo.courseName
- ..cpWantList = r.courseBaseInfo.controlPointSortedList
- .map((e) => e.toModel())
- .toList();
- for (var (i, cp) in player.cpWantList.indexed) {
- cp.sn = i.toString();
- }
- return player;
- }
- }
- class MapWatchServiceImpl extends MapWatchService {
- ApiService get _api => Get.find();
- @override
- Future<MapWatch> newInstanceByMap(MapInfo info) async {
- final r =
- await _api.stub.toMapDetailV2(pb.IdRequest()..id = Int64(info.id));
- final instance = MapWatchImpl(id: info.id)
- ..name = r.mapName
- ..plugMap.gameMap = r.zipImage.toGameMap();
- return instance;
- }
- }
|