Skip to content

Commit

Permalink
Merge pull request #294 from Cupcak3/master
Browse files Browse the repository at this point in the history
Bug Fixes and Features
  • Loading branch information
Cupcak3 authored May 28, 2022
2 parents b3681cd + f018502 commit 99c031d
Show file tree
Hide file tree
Showing 13 changed files with 432 additions and 332 deletions.
22 changes: 20 additions & 2 deletions InventoryKamera/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ private static void ConfigureLogging()
{
var config = new NLog.Config.LoggingConfiguration();

var debugFile = new NLog.Targets.FileTarget("logfile")
{
Layout = "${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}|${level:uppercase=true}|${logger:shortName=True}|${message:withexception=true}",
FileName = "./logging/InventoryKamera.debug.log",
ArchiveFileName = "logging/archives/InventoryKamera.{####}.debug.log",
ArchiveNumbering = NLog.Targets.ArchiveNumberingMode.Date,
ArchiveDateFormat = "yyyyMMddHHmmss",
MaxArchiveFiles = 4,
ConcurrentWrites = true,
KeepFileOpen = true,
ArchiveOldFileOnStartup = true,
ArchiveFileKind = NLog.Targets.FilePathKind.Relative
};

var logFile = new NLog.Targets.FileTarget("logfile")
{
Layout = "${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}|${level:uppercase=true}|${logger:shortName=True}|${message:withexception=true}",
Expand All @@ -51,10 +65,14 @@ private static void ConfigureLogging()
ArchiveFileKind = NLog.Targets.FilePathKind.Relative
};

var logConsole = new NLog.Targets.ConsoleTarget("logconsole");
var logConsole = new NLog.Targets.ConsoleTarget("logconsole")
{
Layout = "${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}|${level:uppercase=true}|${logger:shortName=True}|${message:withexception=true}",
};

config.AddRule(LogLevel.Debug, LogLevel.Fatal, logConsole);
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logFile);
config.AddRule(LogLevel.Debug, LogLevel.Fatal, debugFile);
config.AddRule(LogLevel.Info, LogLevel.Fatal, logFile);

LogManager.Configuration = config;
}
Expand Down
4 changes: 2 additions & 2 deletions InventoryKamera/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.5.0")]
[assembly: AssemblyFileVersion("1.2.5.0")]
[assembly: AssemblyVersion("1.2.6.0")]
[assembly: AssemblyFileVersion("1.2.6.0")]
[assembly: NeutralResourcesLanguage("en")]
112 changes: 47 additions & 65 deletions InventoryKamera/data/InventoryKamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ public class InventoryKamera
private static NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

[JsonProperty]
public List<Character> Characters { get; private set; }
public List<Character> Characters;

[JsonProperty]
public Inventory Inventory = new Inventory();
public Inventory Inventory;

private static List<Artifact> equippedArtifacts;
private static List<Weapon> equippedWeapons;
private List<Artifact> equippedArtifacts;
private List<Weapon> equippedWeapons;
public static Queue<OCRImageCollection> workerQueue;
private static List<Thread> ImageProcessors;
private static volatile bool b_threadCancel = false;
private static int maxProcessors = 2; // TODO: Add support for more processors
private List<Thread> ImageProcessors;
private volatile bool b_threadCancel;
private readonly int NumWorkers;

public bool HasData
{
get { return Characters.Count > 0 || Inventory.Size > 0; }
}

public InventoryKamera()
{
Expand All @@ -37,7 +42,19 @@ public InventoryKamera()
ImageProcessors = new List<Thread>();
workerQueue = new Queue<OCRImageCollection>();

ResetLogging();
b_threadCancel = false;

switch (Properties.Settings.Default.ScannerDelay)
{
case 0:
NumWorkers = 3;
break;
default:
NumWorkers = 2;
break;
}

ResetLogging();
}

public void ResetLogging()
Expand All @@ -56,7 +73,7 @@ public void ResetLogging()
Directory.CreateDirectory("./logging/characters");
Directory.CreateDirectory("./logging/materials");

Logger.Info("Logging directory created");
Logger.Info("Logging directory reset");
}

public void StopImageProcessorWorkers()
Expand All @@ -69,7 +86,7 @@ public void StopImageProcessorWorkers()
public void GatherData()
{
// Initize Image Processors
for (int i = 0; i < maxProcessors; i++)
for (int i = 0; i < NumWorkers; i++)
{
Thread processor = new Thread(ImageProcessorWorker){ IsBackground = true };
processor.Start();
Expand Down Expand Up @@ -133,7 +150,7 @@ public void GatherData()
Navigation.CharacterScreen();
try
{
Characters = CharacterScraper.ScanCharacters();
CharacterScraper.ScanCharacters(ref Characters);
}
catch (ThreadAbortException) { }
catch (Exception ex)
Expand Down Expand Up @@ -241,6 +258,8 @@ public void ImageProcessorWorker()

string weaponPath = $"./logging/weapons/weapon{weapon.Id}/";

if (Properties.Settings.Default.LogScreenshots) Directory.CreateDirectory(weaponPath);

if (weapon.IsValid())
{
if (weapon.Rarity <= (int)Properties.Settings.Default.MinimumWeaponRarity &&
Expand All @@ -260,28 +279,13 @@ public void ImageProcessorWorker()
{
UserInterface.AddError($"Unable to validate information for weapon ID#{weapon.Id}");
string error = "";
if (!weapon.HasValidWeaponName())
{
error += "Invalid weapon name\n";
}
if (!weapon.HasValidRarity())
{
error += "Invalid weapon rarity\n";

}
if (!weapon.HasValidLevel())
{
error += "Invalid weapon level\n";
}
if (!weapon.HasValidRefinementLevel())
{
error += "Invalid refinement level\n";
}
if (!weapon.HasValidEquippedCharacter())
{
error += "Inavlid equipped character\n";
}
if (!weapon.HasValidWeaponName()) error += "Invalid weapon name\n";
if (!weapon.HasValidRarity()) error += "Invalid weapon rarity\n";
if (!weapon.HasValidLevel()) error += "Invalid weapon level\n";
if (!weapon.HasValidRefinementLevel()) error += "Invalid refinement level\n";
if (!weapon.HasValidEquippedCharacter()) error += "Inavlid equipped character\n";
UserInterface.AddError(error + weapon.ToString());
Directory.CreateDirectory(weaponPath);
using (var writer = File.CreateText(weaponPath + "log.txt"))
{
writer.WriteLine($"Version: {Regex.Replace(Assembly.GetExecutingAssembly().GetName().Version.ToString(), @"[.0]*$", string.Empty)}");
Expand All @@ -297,8 +301,6 @@ public void ImageProcessorWorker()

if (!weapon.IsValid() || Properties.Settings.Default.LogScreenshots)
{
Directory.CreateDirectory(weaponPath);

Directory.CreateDirectory(weaponPath + "name");
imageCollection.Bitmaps[0].Save(weaponPath + "name/name.png");
Directory.CreateDirectory(weaponPath + "rarity");
Expand All @@ -309,6 +311,7 @@ public void ImageProcessorWorker()
imageCollection.Bitmaps[2].Save(weaponPath + "refinement/refinement.png");
Directory.CreateDirectory(weaponPath + "equipped");
imageCollection.Bitmaps[4].Save(weaponPath + "equipped/equipped.png");

imageCollection.Bitmaps.Last().Save(weaponPath + "card.png");
}

Expand All @@ -331,6 +334,8 @@ public void ImageProcessorWorker()

string artifactPath = $"./logging/artifacts/artifact{artifact.Id}/";

if (Properties.Settings.Default.LogScreenshots) Directory.CreateDirectory(artifactPath);

if (artifact.IsValid())
{
if (artifact.Rarity <= (int)Properties.Settings.Default.MinimumArtifactRarity &&
Expand All @@ -350,36 +355,15 @@ public void ImageProcessorWorker()
{
UserInterface.AddError($"Unable to validate information for artifact ID#{artifact.Id}");
string error = "";
if (!artifact.HasValidSlot())
{
error += "Invalid artifact gear slot\n";
}
if (!artifact.HasValidSetName())
{
error += "Invalid artifact set name\n";
}
if (!artifact.HasValidRarity())
{
error += "Invalid artifact rarity\n";
}
if (!artifact.HasValidLevel())
{
error += "Invalid artifact level\n";
}
if (!artifact.HasValidMainStat())
{
error += "Invalid artifact main stat\n";
}
if (!artifact.HasValidSubStats())
{
error += "Invalid artifact sub stats\n";
}
if (!artifact.HasValidEquippedCharacter())
{
error += "Invalid equipped character\n";
}
if (!artifact.HasValidSlot()) error += "Invalid artifact gear slot\n";
if (!artifact.HasValidSetName()) error += "Invalid artifact set name\n";
if (!artifact.HasValidRarity()) error += "Invalid artifact rarity\n";
if (!artifact.HasValidLevel()) error += "Invalid artifact level\n";
if (!artifact.HasValidMainStat()) error += "Invalid artifact main stat\n";
if (!artifact.HasValidSubStats()) error += "Invalid artifact sub stats\n";
if (!artifact.HasValidEquippedCharacter()) error += "Invalid equipped character\n";
UserInterface.AddError(error + artifact.ToString());

Directory.CreateDirectory(artifactPath);
using (var writer = File.CreateText(artifactPath + "log.txt"))
{
writer.WriteLine($"Version: {Regex.Replace(Assembly.GetExecutingAssembly().GetName().Version.ToString(), @"[.0]*$", string.Empty)}");
Expand All @@ -395,8 +379,6 @@ public void ImageProcessorWorker()

if (!artifact.IsValid() || Properties.Settings.Default.LogScreenshots)
{
Directory.CreateDirectory(artifactPath);

Directory.CreateDirectory(artifactPath + "slot");
imageCollection.Bitmaps[1].Save(artifactPath + "slot/slot.png");
Directory.CreateDirectory(artifactPath + "set");
Expand Down
46 changes: 29 additions & 17 deletions InventoryKamera/game/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,56 @@ namespace InventoryKamera
[Serializable]
public class Character
{
private string name;

[JsonProperty("key")]
public string Name { get; private set; }
public string Name {

get { return name; }

internal set
{
try
{
name = (string)Scraper.Characters[value.ToLower()]["GOOD"];
}
catch (Exception)
{
name = value;
}
}
}

[JsonProperty("level")]
public int Level { get; private set; }
public int Level { get; internal set; }

[JsonProperty("constellation")]
public int Constellation { get; private set; }
public int Constellation { get; internal set; }

[JsonProperty("ascension")]
public int Ascension
{ get { return AscensionLevel(); } private set { } }
{ get { return AscensionLevel(); } internal set { } }

[JsonProperty("talent")]
public Dictionary<string, int> Talents { get; private set; }
public Dictionary<string, int> Talents { get; internal set; }

[JsonIgnore]
public string Element { get; private set; }
public string Element { get; internal set; }

[JsonIgnore]
public bool Ascended { get; private set; }
public bool Ascended { get; internal set; }

[JsonIgnore]
public int Experience { get; private set; }
public int Experience { get; internal set; }

[JsonIgnore]
public Weapon Weapon { get; private set; }
public Weapon Weapon { get; internal set; }

[JsonIgnore]
public Dictionary<string, Artifact> Artifacts { get; private set; }
public Dictionary<string, Artifact> Artifacts { get; internal set; }

[JsonIgnore]
public WeaponType WeaponType { get; private set; }
public WeaponType WeaponType { get; internal set; }

public Character()
{
Expand All @@ -54,12 +71,7 @@ public Character()

public Character(string _name, string _element, int _level, bool _ascension, int _experience, int _constellation, int[] _talents, WeaponType _weaponType) : this()
{
try
{
Name = (string)Scraper.Characters[_name.ToLower()]["GOOD"];
}
catch (Exception)
{ }

Element = _element;
Level = _level;
Ascended = _ascension;
Expand Down
Loading

0 comments on commit 99c031d

Please sign in to comment.