map_watch.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import 'package:app_business/service/api.dart';
  2. import 'package:track_common/model.dart';
  3. import 'package:track_common/service/map_watch.dart';
  4. import '../generated/base.pb.dart' as pb;
  5. import '../model/game_map.dart';
  6. class MapWatchImpl extends MapWatch {
  7. MapWatchImpl({required super.id});
  8. ApiService get _api => Get.find();
  9. @override
  10. Future<List<EventOnMap>> getEventList(int mapId) async {
  11. final r = await _api.stub
  12. .toUserDetailQueryV2(pb.ToUserDetailQueryRequestV2()..mapId = mapId);
  13. final eventList = <EventOnMap>[];
  14. for (var one in r.list) {
  15. eventList.add(EventOnMap()
  16. ..info.id = one.actId
  17. ..userList = one.userList.map((e) => toAppPlayer(e)).toList());
  18. }
  19. return eventList;
  20. }
  21. PlayerOnMap toAppPlayer(pb.ToOrienteerInGameInfo e) {
  22. final save = e.gameSaveInfo;
  23. final startAt = save.hasStartAt() ? save.startAt.toModel() : DateTime.now();
  24. return PlayerOnMap()
  25. ..info.id = e.userId
  26. ..startAt = startAt
  27. ..duration = DateTime.now().difference(startAt)
  28. ..distance = e.gpsInfo.distance.meter
  29. ..cpListChecked = save.checkedSortedList.isEmpty
  30. ? []
  31. : save.checkedSortedList
  32. .map((e) => ControlPoint()
  33. ..isSuccess = e.isCheckSuccess
  34. ..intId = e.controlPointId.toInt64())
  35. .toList();
  36. }
  37. @override
  38. Future<EventInfo> getEventInfo(int id) async {
  39. final r = await _api.stub.toActionBasicQuery(IdRequest()..id = Int64(id));
  40. final event = EventInfo()
  41. ..name = r.actName
  42. ..cpAllCount = r.totalControlNum;
  43. return event;
  44. }
  45. @override
  46. Future<PlayerInfo> getPlayerInfo(int eventId, int userId) async {
  47. final r = await _api.stub
  48. .toUserInActionBasicQuery(pb.ToUserInActionBasicQueryRequest()
  49. ..actId = eventId
  50. ..userId = userId);
  51. final player = PlayerInfo()
  52. ..id = r.userId
  53. ..name = r.baseInfo.name
  54. ..routeName = r.courseBaseInfo.courseName
  55. ..cpWantList = r.courseBaseInfo.controlPointSortedList
  56. .map((e) => e.toModel())
  57. .toList();
  58. for (var (i, cp) in player.cpWantList.indexed) {
  59. cp.sn = i.toString();
  60. }
  61. return player;
  62. }
  63. }
  64. class MapWatchServiceImpl extends MapWatchService {
  65. ApiService get _api => Get.find();
  66. @override
  67. Future<MapWatch> newInstanceByMap(MapInfo info) async {
  68. final r =
  69. await _api.stub.toMapDetailV2(pb.IdRequest()..id = Int64(info.id));
  70. final instance = MapWatchImpl(id: info.id)
  71. ..name = r.mapName
  72. ..plugMap.gameMap = r.zipImage.toGameMap();
  73. return instance;
  74. }
  75. }