Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cadaei committed Dec 11, 2018
2 parents d7d7f3c + a8eb73e commit e0e3c17
Show file tree
Hide file tree
Showing 19 changed files with 697 additions and 453 deletions.
6 changes: 5 additions & 1 deletion ARKBreedingStats/ARKBreedingStats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Speech" />
Expand Down Expand Up @@ -90,6 +91,7 @@
<Compile Include="ExportedCreatureList.Designer.cs">
<DependentUpon>ExportedCreatureList.cs</DependentUpon>
</Compile>
<Compile Include="FileService.cs" />
<Compile Include="ImportSavegame.cs" />
<Compile Include="ImportExported.cs" />
<Compile Include="local\strings.fr.Designer.cs">
Expand Down Expand Up @@ -661,7 +663,9 @@
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
4 changes: 2 additions & 2 deletions ARKBreedingStats/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ARKBreedingStats
public class Creature : IEquatable<Creature>
{
public string species;
public string name;
public string name = string.Empty;
public Sex sex;
public CreatureStatus status;
// order of the stats is Health, Stamina, Oxygen, Food, Weight, MeleeDamage, Speed, Torpor
Expand Down Expand Up @@ -76,7 +76,7 @@ public Creature()
public Creature(string species, string name, string owner, string tribe, Sex sex, int[] levelsWild, int[] levelsDom = null, double tamingEff = 0, bool isBred = false, double imprinting = 0, int? levelStep = null)
{
this.species = species;
this.name = name;
this.name = name ?? string.Empty;
this.owner = owner;
this.tribe = tribe;
this.sex = sex;
Expand Down
32 changes: 19 additions & 13 deletions ARKBreedingStats/CreatureColored.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;

namespace ARKBreedingStats
{
static class CreatureColored
{
private const string imageFolderName = "img";
private const string cacheFolderName = "cache";
private const string extension = ".png";

public static Bitmap getColoredCreature(int[] colorIds, string species, bool[] enabledColorRegions, int size = 128, int pieSize = 64, bool onlyColors = false, bool dontCache = false)
{
//float[][] hsl = new float[6][];
Expand All @@ -21,18 +26,19 @@ public static Bitmap getColoredCreature(int[] colorIds, string species, bool[] e
using (Graphics graph = Graphics.FromImage(bm))
{
graph.SmoothingMode = SmoothingMode.AntiAlias;
string imgFolder = "img/";
// cachefilename
string cf = imgFolder + "cache/" + species.Substring(0, Math.Min(species.Length, 5)) + "_" + (species + string.Join("", colorIds.Select(i => i.ToString()).ToArray())).GetHashCode().ToString("X8") + ".png";
if (!onlyColors && System.IO.File.Exists(imgFolder + species + ".png") && System.IO.File.Exists(imgFolder + species + "_m.png"))
string imgFolder = Path.Combine(FileService.GetPath(), imageFolderName);
string cacheFolder = Path.Combine(FileService.GetPath(), imageFolderName, cacheFolderName);

string cacheFileName = Path.Combine(cacheFolder, species.Substring(0, Math.Min(species.Length, 5)) + "_" + (species + string.Join("", colorIds.Select(i => i.ToString()).ToArray())).GetHashCode().ToString("X8") + extension);
if (!onlyColors && File.Exists(Path.Combine(imgFolder, species + extension)) && File.Exists(Path.Combine(imgFolder, species + "_m" + extension)))
{
if (!System.IO.File.Exists(cf))
if (!File.Exists(cacheFileName))
{
const int defaultSizeOfTemplates = 256;
Bitmap bmC = new Bitmap(imgFolder + species + ".png");
graph.DrawImage(new Bitmap(imgFolder + species + ".png"), 0, 0, defaultSizeOfTemplates, defaultSizeOfTemplates);
Bitmap bmC = new Bitmap(Path.Combine(imgFolder, species + extension));
graph.DrawImage(new Bitmap(Path.Combine(imgFolder, species + extension)), 0, 0, defaultSizeOfTemplates, defaultSizeOfTemplates);
Bitmap mask = new Bitmap(defaultSizeOfTemplates, defaultSizeOfTemplates);
Graphics.FromImage(mask).DrawImage(new Bitmap(imgFolder + species + "_m.png"), 0, 0, defaultSizeOfTemplates, defaultSizeOfTemplates);
Graphics.FromImage(mask).DrawImage(new Bitmap(Path.Combine(imgFolder, species + "_m" + extension)), 0, 0, defaultSizeOfTemplates, defaultSizeOfTemplates);
float o = 0;
bool imageFine = false;
try
Expand Down Expand Up @@ -98,20 +104,20 @@ public static Bitmap getColoredCreature(int[] colorIds, string species, bool[] e
}
if (imageFine)
{
if (!System.IO.Directory.Exists("img/cache"))
System.IO.Directory.CreateDirectory("img/cache");
bmC.Save(cf); // safe in cache}
if (!Directory.Exists(cacheFolder))
Directory.CreateDirectory(cacheFolder);
bmC.Save(cacheFileName); // safe in cache}
}
}
}
if (System.IO.File.Exists(cf))
if (File.Exists(cacheFileName))
{
graph.CompositingMode = CompositingMode.SourceCopy;
graph.CompositingQuality = CompositingQuality.HighQuality;
graph.InterpolationMode = InterpolationMode.HighQualityBicubic;
graph.SmoothingMode = SmoothingMode.HighQuality;
graph.PixelOffsetMode = PixelOffsetMode.HighQuality;
graph.DrawImage(new Bitmap(cf), 0, 0, size, size);
graph.DrawImage(new Bitmap(cacheFileName), 0, 0, size, size);
}
else
{
Expand Down
75 changes: 75 additions & 0 deletions ARKBreedingStats/FileService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.IO;
using System.Reflection;

namespace ARKBreedingStats
{

public static class FileService
{
private const string jsonFolder = "json";

public const string ValuesJson = "values.json";
public const string KibblesJson = "kibbles.json";
public const string AliasesJson = "aliases.json";
public const string ArkDataJson = "ark_data.json";
public const string ClassicFlyersJson = "classicFlyers.json";
public const string GaiaModJson = "gaiamod.json";

public const string Ocr1680x1050 = "ocr_1680x1050_100.json";
public const string Ocr1920x1080 = "ocr_1920x1080_100.json";
public const string Ocr2560x1440 = "ocr_2560x1440_100.json";
public const string Ocr2680x1080 = "ocr_2680x1080_100.json";
public const string Ocr3440x1440 = "ocr_3440x1440_100.json";

public static readonly string ExeFilePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
public static readonly string ExeLocation = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

/// <summary>
/// Returns a <see cref="FileStream"/> of a file located in the json data folder
/// </summary>
/// <param name="fileName">name of file to read; use FileService constants</param>
/// <returns></returns>
public static FileStream GetJsonFileStream(string fileName)
{
return File.OpenRead(GetJsonPath(fileName));
}

/// <summary>
/// Returns a <see cref="StreamReader"/> of a file located in the json data folder
/// </summary>
/// <param name="fileName">name of file to read; use FileService constants</param>
/// <returns></returns>
public static StreamReader GetJsonFileReader(string fileName)
{
return File.OpenText(GetJsonPath(fileName));
}

/// <summary>
/// Gets the full path for the given filename or the path to the application data folder
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string GetPath(string fileName = null)
{
return Path.Combine(Updater.IsProgramInstalled ? getLocalApplicationDataPath() : ExeLocation, fileName ?? string.Empty);
}

/// <summary>
/// Gets the full path for the given filename or the path to the json folder
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string GetJsonPath(string fileName = null)
{
return Path.Combine(Updater.IsProgramInstalled ? getLocalApplicationDataPath() : ExeLocation, jsonFolder, fileName ?? string.Empty);
}

private static string getLocalApplicationDataPath()
{
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), // C:\Users\xxx\AppData\Local\
Path.GetFileNameWithoutExtension(ExeFilePath) ?? "ARK Smart Breeding"); // ARK Smart Breeding;
}
}
}
15 changes: 14 additions & 1 deletion ARKBreedingStats/FileSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class FileSync
string currentFile = "";
readonly FileSystemWatcher file_watcher;
DateTime lastUpdated;
WatcherChangeTypes lastChangeType;
readonly Action callbackFunction;

public FileSync(string fileName, Action callback)
Expand All @@ -20,6 +21,9 @@ public FileSync(string fileName, Action callback)

// Add the handler for file changes
file_watcher.Changed += onChanged;
file_watcher.Created += onChanged;
file_watcher.Renamed += onChanged;
file_watcher.Deleted += onChanged;

// Update the file watcher's properties
updateProperties();
Expand All @@ -35,6 +39,15 @@ public void changeFile(string newFileName)

private void onChanged(object source, FileSystemEventArgs e)
{
if (e.ChangeType != WatcherChangeTypes.Changed && // default || DropBox
!(e.ChangeType == WatcherChangeTypes.Renamed && lastChangeType == WatcherChangeTypes.Deleted) && // NextCloud
!(e.ChangeType == WatcherChangeTypes.Created && lastChangeType == WatcherChangeTypes.Deleted)) // CloudStation
{
lastChangeType = e.ChangeType;
return;
}
lastChangeType = e.ChangeType;

// Wait until the file is writeable
int numberOfRetries = 5;
int delayOnRetry = 1000;
Expand Down Expand Up @@ -80,7 +93,7 @@ private void updateProperties()
{
// Update the path notify filter and filter of the watcher
file_watcher.Path = Directory.GetParent(currentFile).ToString();
file_watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size;
file_watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.FileName;
file_watcher.Filter = Path.GetFileName(currentFile);
file_watcher.EnableRaisingEvents = true;
}
Expand Down
Loading

0 comments on commit e0e3c17

Please sign in to comment.