diff --git a/ActivityGhosts/ActivityGhosts.cs b/ActivityGhosts/ActivityGhosts.cs index 2f63a3b..5b70aef 100644 --- a/ActivityGhosts/ActivityGhosts.cs +++ b/ActivityGhosts/ActivityGhosts.cs @@ -12,6 +12,7 @@ using GTA.UI; using LemonUI; using LemonUI.Menus; +using LiteDB; namespace ActivityGhosts { @@ -30,11 +31,17 @@ public class ActivityGhosts : Script private NativeItem loadMenuItem; private NativeItem regroupMenuItem; private NativeItem deleteMenuItem; + private readonly string gtaFolder; + private static LiteDatabase db; + private static ILiteCollection activityFiles; public ActivityGhosts() { ghosts = new List(); lastTime = Environment.TickCount; + gtaFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Rockstar Games", "GTA V"); + db = new LiteDatabase(Path.Combine(gtaFolder, "ModSettings", "ActivityGhosts.db")); + activityFiles = db.GetCollection(); LoadSettings(); CreateMenu(); Tick += OnTick; @@ -85,29 +92,39 @@ private void RegroupGhosts() private void LoadGhosts() { - string activitiesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Rockstar Games\\GTA V\\Activities"; + string activitiesPath = Path.Combine(gtaFolder, "Activities"); if (Directory.Exists(activitiesPath)) { - DirectoryInfo dir = new DirectoryInfo(activitiesPath); - FileInfo[] files = dir.GetFiles("*.fit"); - foreach (FileInfo file in files) - { - FitActivityDecoder fit = new FitActivityDecoder(file.FullName); - List points = fit.pointList; - if (points.Count > 1 && Game.Player.Character.Position.DistanceTo2D(new Vector2(points[0].Lat, points[0].Long)) < 50f) + foreach (var file in new DirectoryInfo(activitiesPath).GetFiles("*.fit")) + if (activityFiles.Find(x => x.Name == file.Name).FirstOrDefault() == null) + { + var points = new FitActivityDecoder(file.FullName).pointList; + if (points.Count > 1) + activityFiles.Insert(new ActivityFile() { Name = file.Name, Lat = points[0].Lat, Long = points[0].Long }); + } + foreach (var file in activityFiles.FindAll()) + if (Game.Player.Character.Position.DistanceTo2D(new Vector2(file.Lat, file.Long)) < 50f) { - int offset = ghosts.Count / 2 + 1; - if (ghosts.Count % 2 == 0) - offset *= -1; - points[0].Lat += offset; - float h = Game.Player.Character.Heading; - if ((h > 90f && h < 180f) || (h > 270f && h < 360f)) - points[0].Long -= offset; + string fullName = Path.Combine(activitiesPath, file.Name); + if (System.IO.File.Exists(fullName)) + { + var fit = new FitActivityDecoder(fullName); + if (fit.pointList.Count > 1) + { + int offset = ghosts.Count / 2 + 1; + if (ghosts.Count % 2 == 0) + offset *= -1; + float h = Game.Player.Character.Heading; + if ((h > 45f && h < 135f) || (h > 225f && h < 315f)) + fit.pointList[0].Long += offset; + else + fit.pointList[0].Lat += offset; + ghosts.Add(new Ghost(fit.pointList, fit.sport, fit.startTime)); + } + } else - points[0].Long += offset; - ghosts.Add(new Ghost(points, fit.sport, fit.startTime)); + activityFiles.Delete(file.Id); } - } if (ghosts.Count > 0) { start = World.CreateBlip(Game.Player.Character.Position); @@ -553,4 +570,12 @@ private double DegToRad(float angleDeg) return angleDeg * Math.PI / 180.0f; } } + + public class ActivityFile + { + public int Id { get; set; } + public string Name { get; set; } + public float Lat { get; set; } + public float Long { get; set; } + } } diff --git a/ActivityGhosts/ActivityGhosts.csproj b/ActivityGhosts/ActivityGhosts.csproj index 83f6b10..e7b062a 100644 --- a/ActivityGhosts/ActivityGhosts.csproj +++ b/ActivityGhosts/ActivityGhosts.csproj @@ -37,6 +37,9 @@ D:\Grand Theft Auto V\Scripts\LemonUI.SHVDN3.dll + + ..\packages\LiteDB.5.0.16\lib\net45\LiteDB.dll + D:\Grand Theft Auto V\ScriptHookVDotNet3.dll @@ -48,6 +51,9 @@ + + + COPY "$(TargetPath)" "D:\Grand Theft Auto V\Scripts" diff --git a/ActivityGhosts/packages.config b/ActivityGhosts/packages.config new file mode 100644 index 0000000..f69c748 --- /dev/null +++ b/ActivityGhosts/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file