|
|
@@ -4,12 +4,34 @@ import 'package:common_pub/model/position.dart';
|
|
|
import 'package:common_pub/service/controller.dart';
|
|
|
import 'package:common_pub/ui/map_view/map_view.dart';
|
|
|
import 'package:common_pub/ui/map_view/view_map_trace.dart';
|
|
|
+import '../logger.dart';
|
|
|
import '../service/api.dart' as pb;
|
|
|
import 'package:fixnum/fixnum.dart';
|
|
|
|
|
|
|
|
|
typedef MapId = Int64;
|
|
|
|
|
|
+class Flag{
|
|
|
+ Flag(this.value);
|
|
|
+ int value;
|
|
|
+ Color get color=>Color(value);
|
|
|
+
|
|
|
+ @override
|
|
|
+ bool operator ==(Object other) {
|
|
|
+ if(other is Flag){
|
|
|
+ return value == other.value;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ int get hashCode => value.hashCode;
|
|
|
+
|
|
|
+ static final red = Flag(0xffff0000);
|
|
|
+ static final yellow = Flag(0xffffcb00);
|
|
|
+ static final blue = Flag(0xff00a0ff);
|
|
|
+ static List<Flag> get values =>[red, yellow, blue];
|
|
|
+}
|
|
|
|
|
|
class ActiveInfo{
|
|
|
var id = 0;
|
|
|
@@ -18,6 +40,7 @@ class ActiveInfo{
|
|
|
var userList = <UserInfo>[];
|
|
|
final isHide = false.obs;
|
|
|
|
|
|
+
|
|
|
UserInfo? getUserById(int id){
|
|
|
for (final one in userList){
|
|
|
if(one.gameInfo.userId==id){
|
|
|
@@ -40,7 +63,24 @@ class ActiveInfo{
|
|
|
..gameInfo = info
|
|
|
;
|
|
|
}
|
|
|
+ Future<void> update(pb.ToActionInfo info) async {
|
|
|
+ final newUserList = <UserInfo>[];
|
|
|
+
|
|
|
+ for (final nUser in info.userList) {
|
|
|
+ late UserInfo user;
|
|
|
+ final oUser = getUserById(nUser.userId);
|
|
|
+ if (oUser != null) {
|
|
|
+ user = oUser;
|
|
|
+ await user.update(nUser);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ user = await newUserInfo(nUser);
|
|
|
+ }
|
|
|
|
|
|
+ newUserList.add(user);
|
|
|
+ }
|
|
|
+ userList = newUserList;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
extension ActiveInfoExt on pb.ToActionInfo{
|
|
|
@@ -74,7 +114,8 @@ class UserInfo{
|
|
|
var routeInfo = pb.CourseBaseInfo();
|
|
|
var userInfo = pb.OrienteerBaseInfo();
|
|
|
var trace = <TracePoint>[].obs;
|
|
|
-
|
|
|
+ var flag = Flag.red.obs;
|
|
|
+ DateTime? get startAt => gameInfo.gameSaveInfo.hasStartAt()?gameInfo.gameSaveInfo.startAt.toModel(): null;
|
|
|
|
|
|
Distance get nextDistance {
|
|
|
final one = nextWant;
|
|
|
@@ -112,7 +153,8 @@ class UserInfo{
|
|
|
|
|
|
for(final one in info.gpsInfo.gameGpsInfos){
|
|
|
final t = one.gpsTime.toModel();
|
|
|
- final ts = gameInfo.gameSaveInfo.startAt.toModel().difference(t);
|
|
|
+ final startAt = gameInfo.gameSaveInfo.startAt.toModel();
|
|
|
+ final ts = t.difference(startAt);
|
|
|
if(ts.inMilliseconds>0 && !indexMap.containsKey(ts.inMilliseconds)){
|
|
|
final pos = one.toModel();
|
|
|
trace.add(TracePoint()
|
|
|
@@ -150,10 +192,52 @@ class MapWatchService extends PlugController{
|
|
|
|
|
|
_instance.value = thisInstance;
|
|
|
thisInstance.init();
|
|
|
+ thisInstance.workFlushData();
|
|
|
}
|
|
|
|
|
|
- MapWatchService({required this.id});
|
|
|
+ Future<void> workFlushData()async{
|
|
|
+ while(isActive){
|
|
|
+ try{
|
|
|
+ await flushData();
|
|
|
+ }catch(e){
|
|
|
+ error(e);
|
|
|
+ }
|
|
|
+ await 1.seconds.delay();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ ActiveInfo? getActiveById(int id){
|
|
|
+ for (final one in activeList){
|
|
|
+ if(one.id==id){
|
|
|
+ return one;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> flushData()async{
|
|
|
+ final r = await pb.ApiService.to.stub.toUserDetailQueryV2(pb.ToUserDetailQueryRequestV2(
|
|
|
+ mapId: id.toInt()));
|
|
|
+
|
|
|
+ final newList = <ActiveInfo>[];
|
|
|
+
|
|
|
+ for(final one in r.list){
|
|
|
+ late ActiveInfo info;
|
|
|
+ final old = getActiveById(one.actId);
|
|
|
+ if(old != null){
|
|
|
+ info = old;
|
|
|
+ await info.update(one);
|
|
|
+ }else{
|
|
|
+ info = await one.into();
|
|
|
+ }
|
|
|
+ newList.add(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ activeList.value = newList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ MapWatchService({required this.id});
|
|
|
final MapId id;
|
|
|
String name= '';
|
|
|
final plugMap = PlugMap();
|