Skip to content

Commit

Permalink
Merge pull request #158 from roxaskeyheart/chromatics-3.x
Browse files Browse the repository at this point in the history
Chromatics 3.x
  • Loading branch information
logicallysynced authored Jul 15, 2024
2 parents 7bddfc2 + a52769e commit 20abd25
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 90 deletions.
4 changes: 2 additions & 2 deletions Chromatics/Chromatics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net8.0-windows7.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<StartupObject>Chromatics.Program</StartupObject>
<Version>3.0.8.1</Version>
<Version>3.0.8.2</Version>
<Authors>Danielle Thompson</Authors>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Copyright>Danielle Thompson 2024</Copyright>
Expand Down Expand Up @@ -51,7 +51,7 @@
<PackageReference Include="RGB.NET.Layout" Version="2.2.0-prerelease.1" />
<PackageReference Include="RGB.NET.Presets" Version="2.2.0-prerelease.1" />
<PackageReference Include="Sanford.Multimedia.Midi" Version="6.6.2" />
<PackageReference Include="Sharlayan" Version="8.0.0" />
<PackageReference Include="Sharlayan" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Chromatics/Extensions/FFXIVWeatherExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private WeatherRateIndex GetTerriTypeWeatherRateIndex(TerriType terriType)

private TerriType GetTerritory(string placeName, LangKind lang)
{

var ciPlaceName = placeName.ToLowerInvariant();
var terriType = this.terriTypes.FirstOrDefault(tt => tt.GetName(lang).ToLowerInvariant() == ciPlaceName);
if (terriType == null) throw new ArgumentException("Specified place does not exist.", nameof(placeName));
Expand Down
72 changes: 49 additions & 23 deletions Chromatics/Helpers/FileOperationsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ namespace Chromatics.Helpers
public static class FileOperationsHelper
{
private static bool weatherDataLoaded;
private static WeatherData weatherData;

public static void SaveLayerMappings(ConcurrentDictionary<int, Layer> mappings)
{
var enviroment = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
var path = $"{enviroment}/layers.chromatics3";

try
{
using (var sw = new StreamWriter(path, false))
Expand Down Expand Up @@ -328,9 +329,9 @@ public static PaletteColorModel ImportColorMappings()

try
{
#if DEBUG
Debug.WriteLine("Legacy file detected");
#endif
#if DEBUG
Debug.WriteLine("Legacy file detected");
#endif

var result = new PaletteColorModel();

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

var colorMappings = (LegacyColorMappings)reader.Deserialize(_sr);

_sr.Close();

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

var mapping = (ColorMapping)f.GetValue(result);
var new_mapping = new ColorMapping(mapping.Name, mapping.Type, color);
f.SetValue(result, new_mapping);
f.SetValue(result, new_mapping);
}
}
}
Expand All @@ -378,7 +379,7 @@ public static PaletteColorModel ImportColorMappings()

Logger.WriteConsole(Enums.LoggerTypes.Error, @"Error importing legacy Color Palette.");
return null;

}
else
{
Expand Down Expand Up @@ -572,14 +573,21 @@ public static bool CheckWeatherDataLoaded()
return weatherDataLoaded;
}

public static WeatherData GetWeatherDataLoaded()
{
if (!weatherDataLoaded) return null;

return weatherData;
}

public static string GetCsvData(string url, string csvPath)
{
var http = new HttpClient();
var enviroment = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
var path = enviroment + @"/" + csvPath;

var dataStoreResult = http.GetAsync(new Uri(url)).GetAwaiter().GetResult();

if (File.Exists(path))
{
var fileInfo = new FileInfo(path);
Expand All @@ -599,26 +607,25 @@ public static string GetCsvData(string url, string csvPath)
return path;
}

#if DEBUG
Debug.WriteLine(@"An error occurred downloading the file " + csvPath + @" from URI: " + url);
#endif
#if DEBUG
Debug.WriteLine(@"An error occurred downloading the file " + csvPath + @" from URI: " + url);
#endif

return string.Empty;
}

public static void GetUpdatedWeatherData()
public static WeatherData GetUpdatedWeatherData()
{
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var WeatherKindsOutputPath = directory + @"/weatherKinds.json";
var WeatherRateIndicesOutputPath = directory + @"/weatherRateIndices.json";
var TerriTypesOutputPath = directory + @"/terriTypes.json";

var http = new HttpClient();


// GarlandTools
var dataStoreResult = http.GetAsync(new Uri(@"https://www.garlandtools.org/db/doc/core/en/3/data.json")).GetAwaiter().GetResult();

if (File.Exists(WeatherRateIndicesOutputPath))
{
var fileInfo = new FileInfo(WeatherRateIndicesOutputPath);
Expand All @@ -627,13 +634,24 @@ public static void GetUpdatedWeatherData()
if (fileInfo.LastWriteTimeUtc >= lastModified)
{
weatherDataLoaded = true;
return;
var _weatherRateIndices = JsonConvert.DeserializeObject<List<WeatherRateIndex>>(File.ReadAllText(WeatherRateIndicesOutputPath));
var _terriTypes = JsonConvert.DeserializeObject<List<TerriType>>(File.ReadAllText(TerriTypesOutputPath));
var _weatherKinds = JsonConvert.DeserializeObject<List<Weather>>(File.ReadAllText(WeatherKindsOutputPath));

weatherData = new WeatherData
{
WeatherRateIndices = _weatherRateIndices,
TerriTypes = _terriTypes,
WeatherKinds = _weatherKinds
};

return weatherData;
}
}

Logger.WriteConsole(Enums.LoggerTypes.System, @"Updated FFXIV data is available");
Logger.WriteConsole(Enums.LoggerTypes.System, $"Requesting data from Garland Tools..");

var dataStoreRaw = http.GetStringAsync(new Uri("https://www.garlandtools.org/db/doc/core/en/3/data.json")).GetAwaiter().GetResult();
var dataStore = JObject.Parse(dataStoreRaw);

Expand Down Expand Up @@ -665,11 +683,10 @@ public static void GetUpdatedWeatherData()
}

File.WriteAllText(WeatherRateIndicesOutputPath, JsonConvert.SerializeObject(weatherRateIndices));


// XIVAPI
#if DEBUG
Debug.WriteLine(@"Requesting data from XIVAPI and FFCafe...");
Debug.WriteLine(@"Requesting data from XIVAPI and FFCafe...");
#endif

var terriTypes = new List<TerriType>();
Expand Down Expand Up @@ -701,7 +718,7 @@ public static void GetUpdatedWeatherData()
page++;
}

var cafeCsvRaw = http.GetStreamAsync(new Uri(@"https://raw.githubusercontent.com/thewakingsands/ffxiv-datamining-cn/master/PlaceName.csv")).GetAwaiter().GetResult();
var cafeCsvRaw = http.GetStreamAsync(new Uri(@"https://raw.githubusercontent.com/xivapi/ffxiv-datamining/master/csv/PlaceName.csv")).GetAwaiter().GetResult();
using var cafeSr = new StreamReader(cafeCsvRaw);
using var cafeCsv = new CsvReader(cafeSr, CultureInfo.InvariantCulture);
for (var i = 0; i < 3; i++) cafeCsv.Read();
Expand All @@ -723,7 +740,7 @@ public static void GetUpdatedWeatherData()
Logger.WriteConsole(Enums.LoggerTypes.Error, $"XIVAPI: Data is not continuous and/or sorted in ascending order.");
ttLastN = terriType.Id;
}

File.WriteAllText(TerriTypesOutputPath, JsonConvert.SerializeObject(terriTypes));

var weatherKinds = new List<Weather>();
Expand All @@ -741,7 +758,7 @@ public static void GetUpdatedWeatherData()
foreach (var child in dataStore2["Results"].Children())
{
var id = child["ID"].ToObject<int>();

weatherKinds.Add(new Weather
{
Id = id,
Expand All @@ -755,7 +772,7 @@ public static void GetUpdatedWeatherData()
page++;
}

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

Logger.WriteConsole(Enums.LoggerTypes.System, $"Successfully updated internal database from Garland Tools");
weatherDataLoaded = true;

weatherData = new WeatherData
{
WeatherRateIndices = weatherRateIndices,
TerriTypes = terriTypes,
WeatherKinds = weatherKinds
};

return weatherData;
}
}
}
25 changes: 25 additions & 0 deletions Chromatics/Helpers/GameHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Chromatics.Core;
using Chromatics.Models;
using FFXIVWeather.Models;
using RGB.NET.Core;
using Sharlayan.Core.Enums;
using Sharlayan.Models.ReadResults;
Expand Down Expand Up @@ -386,5 +387,29 @@ public static string GetJobClassDynamicLayerDescriptions(Actor.Job jobClass, str

return @"";
}

public static string GetZoneNameById(uint id, string language = "en")
{
var data = FileOperationsHelper.GetWeatherDataLoaded();

if (data == null) return null;

var terriTypes = data.TerriTypes;
var terriType = terriTypes.FirstOrDefault(tt => tt.Id == id);
if (terriType == null)
{
return null; // or throw an exception, or return a default value
}

return language.ToLower() switch
{
"en" => terriType.NameEn,
"de" => terriType.NameDe,
"fr" => terriType.NameFr,
"ja" => terriType.NameJa,
"zh" => terriType.NameZh,
_ => null // or throw an exception, or return a default value
};
}
}
}
3 changes: 2 additions & 1 deletion Chromatics/Layers/BaseLayers/ReactiveWeather.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public override void Process(IMappingLayer layer)
var getCurrentPlayer = _memoryHandler.Reader.GetCurrentPlayer();
if (getCurrentPlayer.Entity == null) return;

var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
//var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
var currentZone = GameHelper.GetZoneNameById(getCurrentPlayer.Entity.MapTerritory);

if (currentZone != "???" && currentZone != "")
{
Expand Down
3 changes: 2 additions & 1 deletion Chromatics/Layers/DynamicLayers/ReactiveWeatherHighlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public override void Process(IMappingLayer layer)
var getCurrentPlayer = _memoryHandler.Reader.GetCurrentPlayer();
if (getCurrentPlayer.Entity == null) return;

var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
//var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
var currentZone = GameHelper.GetZoneNameById(getCurrentPlayer.Entity.MapTerritory);

if (currentZone != "???" && currentZone != "")
{
Expand Down
5 changes: 4 additions & 1 deletion Chromatics/Layers/EffectLayers/GoldSaucerVegas.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Chromatics.Core;
using Chromatics.Extensions.RGB.NET;
using Chromatics.Helpers;
using Chromatics.Interfaces;
using RGB.NET.Core;
using RGB.NET.Presets.Decorators;
Expand Down Expand Up @@ -80,7 +81,9 @@ public override void Process(IMappingLayer layer)
var getCurrentPlayer = _memoryHandler.Reader.GetCurrentPlayer();
if (getCurrentPlayer.Entity == null) return;

var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
//var currentZone = ZoneLookup.GetZoneInfo(getCurrentPlayer.Entity.MapTerritory).Name.English;
var currentZone = GameHelper.GetZoneNameById(getCurrentPlayer.Entity.MapTerritory);

var baseLayer = MappingLayers.GetLayers().Values.Where(x => x.rootLayerType == Enums.LayerType.BaseLayer && x.deviceType == layer.deviceType).FirstOrDefault();

if (baseLayer.deviceType == RGBDeviceType.Keyboard)
Expand Down
Loading

0 comments on commit 20abd25

Please sign in to comment.