Skip to content

Commit 20abd25

Browse files
Merge pull request #158 from roxaskeyheart/chromatics-3.x
Chromatics 3.x
2 parents 7bddfc2 + a52769e commit 20abd25

11 files changed

Lines changed: 124 additions & 90 deletions

File tree

Chromatics/Chromatics.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFramework>net8.0-windows7.0</TargetFramework>
66
<UseWindowsForms>true</UseWindowsForms>
77
<StartupObject>Chromatics.Program</StartupObject>
8-
<Version>3.0.8.1</Version>
8+
<Version>3.0.8.2</Version>
99
<Authors>Danielle Thompson</Authors>
1010
<ApplicationManifest>app.manifest</ApplicationManifest>
1111
<Copyright>Danielle Thompson 2024</Copyright>
@@ -51,7 +51,7 @@
5151
<PackageReference Include="RGB.NET.Layout" Version="2.2.0-prerelease.1" />
5252
<PackageReference Include="RGB.NET.Presets" Version="2.2.0-prerelease.1" />
5353
<PackageReference Include="Sanford.Multimedia.Midi" Version="6.6.2" />
54-
<PackageReference Include="Sharlayan" Version="8.0.0" />
54+
<PackageReference Include="Sharlayan" Version="8.0.1" />
5555
</ItemGroup>
5656

5757
<ItemGroup>

Chromatics/Extensions/FFXIVWeatherExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ private WeatherRateIndex GetTerriTypeWeatherRateIndex(TerriType terriType)
115115

116116
private TerriType GetTerritory(string placeName, LangKind lang)
117117
{
118+
118119
var ciPlaceName = placeName.ToLowerInvariant();
119120
var terriType = this.terriTypes.FirstOrDefault(tt => tt.GetName(lang).ToLowerInvariant() == ciPlaceName);
120121
if (terriType == null) throw new ArgumentException("Specified place does not exist.", nameof(placeName));

Chromatics/Helpers/FileOperationsHelper.cs

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ namespace Chromatics.Helpers
2929
public static class FileOperationsHelper
3030
{
3131
private static bool weatherDataLoaded;
32+
private static WeatherData weatherData;
3233

3334
public static void SaveLayerMappings(ConcurrentDictionary<int, Layer> mappings)
3435
{
3536
var enviroment = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
3637
var path = $"{enviroment}/layers.chromatics3";
37-
38+
3839
try
3940
{
4041
using (var sw = new StreamWriter(path, false))
@@ -328,9 +329,9 @@ public static PaletteColorModel ImportColorMappings()
328329

329330
try
330331
{
331-
#if DEBUG
332-
Debug.WriteLine("Legacy file detected");
333-
#endif
332+
#if DEBUG
333+
Debug.WriteLine("Legacy file detected");
334+
#endif
334335

335336
var result = new PaletteColorModel();
336337

@@ -345,7 +346,7 @@ public static PaletteColorModel ImportColorMappings()
345346
var _sr = new MemoryStream(bytes);
346347

347348
var colorMappings = (LegacyColorMappings)reader.Deserialize(_sr);
348-
349+
349350
_sr.Close();
350351

351352
foreach (var p in colorMappings.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
@@ -358,7 +359,7 @@ public static PaletteColorModel ImportColorMappings()
358359

359360
var mapping = (ColorMapping)f.GetValue(result);
360361
var new_mapping = new ColorMapping(mapping.Name, mapping.Type, color);
361-
f.SetValue(result, new_mapping);
362+
f.SetValue(result, new_mapping);
362363
}
363364
}
364365
}
@@ -378,7 +379,7 @@ public static PaletteColorModel ImportColorMappings()
378379

379380
Logger.WriteConsole(Enums.LoggerTypes.Error, @"Error importing legacy Color Palette.");
380381
return null;
381-
382+
382383
}
383384
else
384385
{
@@ -572,14 +573,21 @@ public static bool CheckWeatherDataLoaded()
572573
return weatherDataLoaded;
573574
}
574575

576+
public static WeatherData GetWeatherDataLoaded()
577+
{
578+
if (!weatherDataLoaded) return null;
579+
580+
return weatherData;
581+
}
582+
575583
public static string GetCsvData(string url, string csvPath)
576584
{
577585
var http = new HttpClient();
578586
var enviroment = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
579587
var path = enviroment + @"/" + csvPath;
580588

581589
var dataStoreResult = http.GetAsync(new Uri(url)).GetAwaiter().GetResult();
582-
590+
583591
if (File.Exists(path))
584592
{
585593
var fileInfo = new FileInfo(path);
@@ -599,26 +607,25 @@ public static string GetCsvData(string url, string csvPath)
599607
return path;
600608
}
601609

602-
#if DEBUG
603-
Debug.WriteLine(@"An error occurred downloading the file " + csvPath + @" from URI: " + url);
604-
#endif
610+
#if DEBUG
611+
Debug.WriteLine(@"An error occurred downloading the file " + csvPath + @" from URI: " + url);
612+
#endif
605613

606614
return string.Empty;
607615
}
608616

609-
public static void GetUpdatedWeatherData()
617+
public static WeatherData GetUpdatedWeatherData()
610618
{
611619
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
612620
var WeatherKindsOutputPath = directory + @"/weatherKinds.json";
613621
var WeatherRateIndicesOutputPath = directory + @"/weatherRateIndices.json";
614622
var TerriTypesOutputPath = directory + @"/terriTypes.json";
615623

616624
var http = new HttpClient();
617-
618625

619626
// GarlandTools
620627
var dataStoreResult = http.GetAsync(new Uri(@"https://www.garlandtools.org/db/doc/core/en/3/data.json")).GetAwaiter().GetResult();
621-
628+
622629
if (File.Exists(WeatherRateIndicesOutputPath))
623630
{
624631
var fileInfo = new FileInfo(WeatherRateIndicesOutputPath);
@@ -627,13 +634,24 @@ public static void GetUpdatedWeatherData()
627634
if (fileInfo.LastWriteTimeUtc >= lastModified)
628635
{
629636
weatherDataLoaded = true;
630-
return;
637+
var _weatherRateIndices = JsonConvert.DeserializeObject<List<WeatherRateIndex>>(File.ReadAllText(WeatherRateIndicesOutputPath));
638+
var _terriTypes = JsonConvert.DeserializeObject<List<TerriType>>(File.ReadAllText(TerriTypesOutputPath));
639+
var _weatherKinds = JsonConvert.DeserializeObject<List<Weather>>(File.ReadAllText(WeatherKindsOutputPath));
640+
641+
weatherData = new WeatherData
642+
{
643+
WeatherRateIndices = _weatherRateIndices,
644+
TerriTypes = _terriTypes,
645+
WeatherKinds = _weatherKinds
646+
};
647+
648+
return weatherData;
631649
}
632650
}
633-
651+
634652
Logger.WriteConsole(Enums.LoggerTypes.System, @"Updated FFXIV data is available");
635653
Logger.WriteConsole(Enums.LoggerTypes.System, $"Requesting data from Garland Tools..");
636-
654+
637655
var dataStoreRaw = http.GetStringAsync(new Uri("https://www.garlandtools.org/db/doc/core/en/3/data.json")).GetAwaiter().GetResult();
638656
var dataStore = JObject.Parse(dataStoreRaw);
639657

@@ -665,11 +683,10 @@ public static void GetUpdatedWeatherData()
665683
}
666684

667685
File.WriteAllText(WeatherRateIndicesOutputPath, JsonConvert.SerializeObject(weatherRateIndices));
668-
669686

670687
// XIVAPI
671688
#if DEBUG
672-
Debug.WriteLine(@"Requesting data from XIVAPI and FFCafe...");
689+
Debug.WriteLine(@"Requesting data from XIVAPI and FFCafe...");
673690
#endif
674691

675692
var terriTypes = new List<TerriType>();
@@ -701,7 +718,7 @@ public static void GetUpdatedWeatherData()
701718
page++;
702719
}
703720

704-
var cafeCsvRaw = http.GetStreamAsync(new Uri(@"https://raw.githubusercontent.com/thewakingsands/ffxiv-datamining-cn/master/PlaceName.csv")).GetAwaiter().GetResult();
721+
var cafeCsvRaw = http.GetStreamAsync(new Uri(@"https://raw.githubusercontent.com/xivapi/ffxiv-datamining/master/csv/PlaceName.csv")).GetAwaiter().GetResult();
705722
using var cafeSr = new StreamReader(cafeCsvRaw);
706723
using var cafeCsv = new CsvReader(cafeSr, CultureInfo.InvariantCulture);
707724
for (var i = 0; i < 3; i++) cafeCsv.Read();
@@ -723,7 +740,7 @@ public static void GetUpdatedWeatherData()
723740
Logger.WriteConsole(Enums.LoggerTypes.Error, $"XIVAPI: Data is not continuous and/or sorted in ascending order.");
724741
ttLastN = terriType.Id;
725742
}
726-
743+
727744
File.WriteAllText(TerriTypesOutputPath, JsonConvert.SerializeObject(terriTypes));
728745

729746
var weatherKinds = new List<Weather>();
@@ -741,7 +758,7 @@ public static void GetUpdatedWeatherData()
741758
foreach (var child in dataStore2["Results"].Children())
742759
{
743760
var id = child["ID"].ToObject<int>();
744-
761+
745762
weatherKinds.Add(new Weather
746763
{
747764
Id = id,
@@ -755,7 +772,7 @@ public static void GetUpdatedWeatherData()
755772
page++;
756773
}
757774

758-
var cafeCsvRaw = http.GetStreamAsync(new Uri(@"https://raw.githubusercontent.com/thewakingsands/ffxiv-datamining-cn/master/Weather.csv")).GetAwaiter().GetResult();
775+
var cafeCsvRaw = http.GetStreamAsync(new Uri(@"https://raw.githubusercontent.com/xivapi/ffxiv-datamining/master/csv/Weather.csv")).GetAwaiter().GetResult();
759776
using var cafeSr = new StreamReader(cafeCsvRaw);
760777
using var cafeCsv = new CsvReader(cafeSr, CultureInfo.InvariantCulture);
761778
for (var i = 0; i < 3; i++) cafeCsv.Read();
@@ -782,6 +799,15 @@ public static void GetUpdatedWeatherData()
782799

783800
Logger.WriteConsole(Enums.LoggerTypes.System, $"Successfully updated internal database from Garland Tools");
784801
weatherDataLoaded = true;
802+
803+
weatherData = new WeatherData
804+
{
805+
WeatherRateIndices = weatherRateIndices,
806+
TerriTypes = terriTypes,
807+
WeatherKinds = weatherKinds
808+
};
809+
810+
return weatherData;
785811
}
786812
}
787813
}

Chromatics/Helpers/GameHelper.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Chromatics.Core;
22
using Chromatics.Models;
3+
using FFXIVWeather.Models;
34
using RGB.NET.Core;
45
using Sharlayan.Core.Enums;
56
using Sharlayan.Models.ReadResults;
@@ -386,5 +387,29 @@ public static string GetJobClassDynamicLayerDescriptions(Actor.Job jobClass, str
386387

387388
return @"";
388389
}
390+
391+
public static string GetZoneNameById(uint id, string language = "en")
392+
{
393+
var data = FileOperationsHelper.GetWeatherDataLoaded();
394+
395+
if (data == null) return null;
396+
397+
var terriTypes = data.TerriTypes;
398+
var terriType = terriTypes.FirstOrDefault(tt => tt.Id == id);
399+
if (terriType == null)
400+
{
401+
return null; // or throw an exception, or return a default value
402+
}
403+
404+
return language.ToLower() switch
405+
{
406+
"en" => terriType.NameEn,
407+
"de" => terriType.NameDe,
408+
"fr" => terriType.NameFr,
409+
"ja" => terriType.NameJa,
410+
"zh" => terriType.NameZh,
411+
_ => null // or throw an exception, or return a default value
412+
};
413+
}
389414
}
390415
}

Chromatics/Layers/BaseLayers/ReactiveWeather.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public override void Process(IMappingLayer layer)
115115
var getCurrentPlayer = _memoryHandler.Reader.GetCurrentPlayer();
116116
if (getCurrentPlayer.Entity == null) return;
117117

118-
var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
118+
//var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
119+
var currentZone = GameHelper.GetZoneNameById(getCurrentPlayer.Entity.MapTerritory);
119120

120121
if (currentZone != "???" && currentZone != "")
121122
{

Chromatics/Layers/DynamicLayers/ReactiveWeatherHighlight.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public override void Process(IMappingLayer layer)
9898
var getCurrentPlayer = _memoryHandler.Reader.GetCurrentPlayer();
9999
if (getCurrentPlayer.Entity == null) return;
100100

101-
var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
101+
//var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
102+
var currentZone = GameHelper.GetZoneNameById(getCurrentPlayer.Entity.MapTerritory);
102103

103104
if (currentZone != "???" && currentZone != "")
104105
{

Chromatics/Layers/EffectLayers/GoldSaucerVegas.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Chromatics.Core;
22
using Chromatics.Extensions.RGB.NET;
3+
using Chromatics.Helpers;
34
using Chromatics.Interfaces;
45
using RGB.NET.Core;
56
using RGB.NET.Presets.Decorators;
@@ -80,7 +81,9 @@ public override void Process(IMappingLayer layer)
8081
var getCurrentPlayer = _memoryHandler.Reader.GetCurrentPlayer();
8182
if (getCurrentPlayer.Entity == null) return;
8283

83-
var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
84+
//var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
85+
var currentZone = GameHelper.GetZoneNameById(getCurrentPlayer.Entity.MapTerritory);
86+
8487
var baseLayer = MappingLayers.GetLayers().Values.Where(x => x.rootLayerType == Enums.LayerType.BaseLayer && x.deviceType == layer.deviceType).FirstOrDefault();
8588

8689
if (baseLayer.deviceType == RGBDeviceType.Keyboard)

0 commit comments

Comments
 (0)