Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Nov 19, 2023
2 parents bc7a969 + 3bb7d9b commit 3ec4e1b
Show file tree
Hide file tree
Showing 25 changed files with 2,030 additions and 174 deletions.
3 changes: 3 additions & 0 deletions ARKBreedingStats/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@
<setting name="AskSaveSettingsOnClose" serializeAs="String">
<value>True</value>
</setting>
<setting name="KeepMultipliersForNewLibrary" serializeAs="String">
<value>True</value>
</setting>
</ARKBreedingStats.Properties.Settings>
</userSettings>
</configuration>
4 changes: 2 additions & 2 deletions ARKBreedingStats/CreatureBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ void SetParentLabel(Label l, string lbText = null, bool clickable = false)
}
else if (_creature.isDomesticated)
{
SetParentLabel(LbMotherAndWildInfo, "found wild " + _creature.levelFound + (_creature.tamingEff >= 0 ? ", tamed with TE: " + (_creature.tamingEff * 100).ToString("N1") + "%" : ", TE unknown."));
SetParentLabel(LbMotherAndWildInfo, "was level " + _creature.levelFound + " when wild" + (_creature.tamingEff >= 0 ? ", tamed with TE: " + (_creature.tamingEff * 100).ToString("N1") + "%" : ", TE unknown."));
}
else
{
SetParentLabel(LbMotherAndWildInfo, "found wild " + _creature.levelFound);
SetParentLabel(LbMotherAndWildInfo, "is wild level " + _creature.levelFound);
}
statsDisplay1.SetCreatureValues(_creature);
labelNotes.Text = _creature.note;
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions ARKBreedingStats/Form1.collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ private void NewCollection(bool resetCollection = false)
}

// use previously used multipliers again in the new file
var oldMultipliers = _creatureCollection.serverMultipliers
?? Values.V.serverMultipliersPresets.GetPreset(ServerMultipliersPresets.Official);
var oldMultipliers = _creatureCollection.serverMultipliers;
var asaMode = _creatureCollection.Game == Ark.Asa;

if (!Properties.Settings.Default.KeepMultipliersForNewLibrary)
{
oldMultipliers = null;
asaMode = true; // default to ASA
}

if (oldMultipliers == null)
oldMultipliers = Values.V.serverMultipliersPresets.GetPreset(ServerMultipliersPresets.Official);

_creatureCollection = new CreatureCollection
{
serverMultipliers = oldMultipliers,
Expand Down Expand Up @@ -514,7 +522,7 @@ private bool LoadCollectionFile(string filePath, bool keepCurrentCreatures = fal

if (keepCurrentCreatures)
{
creatureWasAdded = previouslyLoadedCreatureCollection.MergeCreatureList(_creatureCollection.creatures);
creatureWasAdded = previouslyLoadedCreatureCollection.MergeCreatureList(_creatureCollection.creatures, removeCreatures: _creatureCollection.DeletedCreatureGuids);
_creatureCollection = previouslyLoadedCreatureCollection;
}
else
Expand Down Expand Up @@ -800,6 +808,7 @@ private bool ImportExportGunFiles(string[] filePaths, out bool creatureAdded, ou
bool? multipliersImportSuccessful = null;
string serverImportResult = null;
bool creatureAlreadyExists = false;
var gameSettingBefore = _creatureCollection.Game;

foreach (var filePath in filePaths)
{
Expand All @@ -826,13 +835,29 @@ private bool ImportExportGunFiles(string[] filePaths, out bool creatureAdded, ou
}
}

if (!string.IsNullOrEmpty(serverMultipliersHash) && _creatureCollection.ServerMultipliersHash != serverMultipliersHash)
if (lastCreatureFilePath != null && !string.IsNullOrEmpty(serverMultipliersHash) && _creatureCollection.ServerMultipliersHash != serverMultipliersHash)
{
// current server multipliers might be outdated, import them again
var serverMultiplierFilePath = Path.Combine(Path.GetDirectoryName(lastCreatureFilePath), "Servers", serverMultipliersHash + ".sav");
// for ASE the export gun create a .sav file containing a json, for ASA directly a .json file
var serverMultiplierFilePath = Path.Combine(Path.GetDirectoryName(lastCreatureFilePath), "Servers", serverMultipliersHash + ".json");
if (!File.Exists(serverMultiplierFilePath))
serverMultiplierFilePath = Path.Combine(Path.GetDirectoryName(lastCreatureFilePath), "Servers", serverMultipliersHash + ".sav");

multipliersImportSuccessful = ImportExportGun.ImportServerMultipliers(_creatureCollection, serverMultiplierFilePath, serverMultipliersHash, out serverImportResult);
}

if (multipliersImportSuccessful == true)
{
if (_creatureCollection.Game != gameSettingBefore)
{
// ASA setting changed
var loadAsa = gameSettingBefore != Ark.Asa;
ReloadModValuesOfCollectionIfNeeded(loadAsa, false, false);
}

ApplySettingsToValues();
}

lastAddedCreature = newCreatures.LastOrDefault();
if (lastAddedCreature != null)
{
Expand Down
12 changes: 5 additions & 7 deletions ARKBreedingStats/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,7 @@ private void ApplySettingsToValues()
{
// apply multipliers
Values.V.ApplyMultipliers(_creatureCollection, cbEventMultipliers.Checked);
tamingControl1.SetTamingMultipliers(Values.V.currentServerMultipliers.TamingSpeedMultiplier,
Values.V.currentServerMultipliers.DinoCharacterFoodDrainMultiplier);
tamingControl1.SetServerMultipliers(Values.V.currentServerMultipliers);

ColorModeColors.SetColors((ColorModeColors.AsbColorMode)Properties.Settings.Default.ColorMode);
RecalculateAllCreaturesValues();
Expand Down Expand Up @@ -1871,7 +1870,7 @@ private void SetCreatureStatus(IEnumerable<Creature> cs, CreatureStatus s)
if (s.HasFlag(CreatureStatus.Dead) ^ deadStatusWasSet)
{
LibraryInfo.ClearInfo();
_creatureCollection.ResetExistingColors(speciesIfOnlyOne);
_creatureCollection.ResetExistingColors(speciesIfOnlyOne?.blueprintPath);
}
FilterLibRecalculate();
UpdateStatusBar();
Expand Down Expand Up @@ -2581,8 +2580,7 @@ private void ShowLevelsInOverlay()
Values.V.currentServerMultipliers.TamingSpeedMultiplier, foodName,
speciesSelector1.SelectedSpecies.taming.nonViolent);
Taming.TamingTimes(speciesSelector1.SelectedSpecies, levelWild,
Values.V.currentServerMultipliers.TamingSpeedMultiplier,
Values.V.currentServerMultipliers.DinoCharacterFoodDrainMultiplier, foodName, foodNeeded, out _,
Values.V.currentServerMultipliers, foodName, foodNeeded, out _,
out TimeSpan duration, out int narcoBerries, out int ascerbicMushrooms, out int narcotics,
out int bioToxines, out double te, out _, out int bonusLevel, out _);
extraText += $"\nTaming takes {(int)duration.TotalHours}:{duration:mm':'ss} with {foodNeeded} × {foodName}"
Expand Down Expand Up @@ -2852,8 +2850,7 @@ private void ApplyEvolutionMultipliers()
{
Values.V.ApplyMultipliers(_creatureCollection, cbEventMultipliers.Checked, false);

tamingControl1.SetTamingMultipliers(Values.V.currentServerMultipliers.TamingSpeedMultiplier,
Values.V.currentServerMultipliers.DinoCharacterFoodDrainMultiplier);
tamingControl1.SetServerMultipliers(Values.V.currentServerMultipliers);
breedingPlan1.UpdateBreedingData();
raisingControl1.UpdateRaisingData();
}
Expand Down Expand Up @@ -3349,6 +3346,7 @@ private void ProcessDroppedFiles(string[] files)
_exportedCreatureList.LoadFiles(files);
break;
case ".sav":
case ".json":
ImportExportGunFiles(files, out _, out _);
break;
case ".asb":
Expand Down
1 change: 1 addition & 0 deletions ARKBreedingStats/Form1.extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using ARKBreedingStats.importExportGun;
using ARKBreedingStats.utils;
using ARKBreedingStats.ocr;

Expand Down
121 changes: 70 additions & 51 deletions ARKBreedingStats/Form1.importExported.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,62 +70,78 @@ private void btImportLastExported_Click(object sender, EventArgs e)
/// </summary>
private void ImportLastExportedCreature()
{
if (Utils.GetFirstImportExportFolder(out string folder))
if (!Utils.GetFirstImportExportFolder(out string folder))
{
var files = Directory.GetFiles(folder);
if (files.Length == 0)
if (MessageBox.Show("There is no folder set where the exported creatures are located, or the set folder does not exist. Set this folder in the settings. " +
"Usually the folder path ends with\n" + @"…\ARK\ShooterGame\Saved\DinoExports\<ID>" + "\n\nOpen the settings-page?",
$"No default export-folder set - {Utils.ApplicationNameVersion}", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
{
// some users forget to select the id folder where the export files are located. Check if that's the case
FileInfo lastExportFile = null;
if (Path.GetFileName(folder) == "DinoExports")
{
// check subfolders for export files
var subFolders = Directory.GetDirectories(folder);
foreach (var sf in subFolders)
{
var d = new DirectoryInfo(sf);
var fs = d.GetFiles("*.ini");
if (!fs.Any()) continue;
var expFile = fs.OrderByDescending(f => f.LastWriteTime).First();
if (lastExportFile == null || expFile.LastWriteTime > lastExportFile.LastWriteTime)
lastExportFile = expFile;
}
}
OpenSettingsDialog(Settings.SettingsTabPages.ExportedImport);
}
return;
}

if (lastExportFile == null)
var files = Directory.GetFiles(folder);
if (files.Length == 0)
{
// some users forget to select the id folder where the export files are located. Check if that's the case
FileInfo lastExportFile = null;
if (Path.GetFileName(folder) == "DinoExports")
{
// check subfolders for export files
var subFolders = Directory.GetDirectories(folder);
foreach (var sf in subFolders)
{
MessageBoxes.ShowMessageBox(
$"No exported creature-file found in the set folder\n{folder}\nYou have to export a creature first ingame.\n\n" +
"You may also want to check the set folder in the settings. Usually the folder path ends with\n" +
@"…\ARK\ShooterGame\Saved\DinoExports\<ID>",
$"No files found");
return;
var d = new DirectoryInfo(sf);
var fs = d.GetFiles("*.ini");
if (!fs.Any()) continue;
var expFile = fs.OrderByDescending(f => f.LastWriteTime).First();
if (lastExportFile == null || expFile.LastWriteTime > lastExportFile.LastWriteTime)
lastExportFile = expFile;
}
}

if (MessageBox.Show(
$"No exported creature-file found in the set folder\n{folder}\n\nThere seems to be an export file in a subfolder, do you want to use this folder instead?\n{lastExportFile.DirectoryName}",
$"Use subfolder with export file? - {Utils.ApplicationNameVersion}",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
var exportFolders = Properties.Settings.Default.ExportCreatureFolders;
var firstExportFolder = ATImportExportedFolderLocation.CreateFromString(exportFolders[0]);
firstExportFolder.FolderPath = lastExportFile.DirectoryName;
exportFolders[0] = firstExportFolder.ToString();

ExtractExportedFileInExtractor(lastExportFile.FullName);
}
if (lastExportFile == null)
{
MessageBoxes.ShowMessageBox(
$"No exported creature-file found in the set folder\n{folder}\nYou have to export a creature first ingame.\n\n" +
"You may also want to check the set folder in the settings. Usually the folder path ends with\n" +
@"…\ARK\ShooterGame\Saved\DinoExports\<ID>",
$"No files found");
return;
}

ExtractExportedFileInExtractor(files.OrderByDescending(File.GetLastWriteTime).First());
if (MessageBox.Show(
$"No exported creature-file found in the set folder\n{folder}\n\nThere seems to be an export file in a subfolder, do you want to use this folder instead?\n{lastExportFile.DirectoryName}",
$"Use subfolder with export file? - {Utils.ApplicationNameVersion}",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
var exportFolders = Properties.Settings.Default.ExportCreatureFolders;
var firstExportFolder = ATImportExportedFolderLocation.CreateFromString(exportFolders[0]);
firstExportFolder.FolderPath = lastExportFile.DirectoryName;
exportFolders[0] = firstExportFolder.ToString();

ExtractExportedFileInExtractor(lastExportFile.FullName);
}
return;
}

if (MessageBox.Show("There is no folder set where the exported creatures are located, or the set folder does not exist. Set this folder in the settings. " +
"Usually the folder path ends with\n" + @"…\ARK\ShooterGame\Saved\DinoExports\<ID>" + "\n\nOpen the settings-page?",
$"No default export-folder set - {Utils.ApplicationNameVersion}", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
var newestExportFile = files.OrderByDescending(File.GetLastWriteTime).First();

switch (Path.GetExtension(newestExportFile))
{
OpenSettingsDialog(Settings.SettingsTabPages.ExportedImport);
case ".ini":
// ini files need to be processed by the extractor
ExtractExportedFileInExtractor(newestExportFile);
return;
case ".sav":
case ".json":
// export gun mod creature exports can be just added
var creature = ImportExportedAddIfPossible(newestExportFile);
// display imported creature in the extractor to allow adjustments
_ignoreNextMessageLabel = true;
EditCreatureInTester(creature);
return;
}
}

Expand Down Expand Up @@ -165,10 +181,9 @@ private void ImportExportedAddIfPossible_WatcherThread(string filePath, importEx
}

/// <summary>
/// Import exported file. Used by a fileWatcher.
/// Import exported file. Used by a fileWatcher. Returns creature if added successfully.
/// </summary>
/// <param name="filePath"></param>
private void ImportExportedAddIfPossible(string filePath)
private Creature ImportExportedAddIfPossible(string filePath)
{
bool alreadyExists;
bool addedToLibrary = false;
Expand All @@ -181,7 +196,7 @@ private void ImportExportedAddIfPossible(string filePath)
{
case ".ini":
var loadResult = ExtractExportedFileInExtractor(filePath);
if (loadResult == null) return;
if (loadResult == null) return null;
alreadyExists = loadResult.Value;

uniqueExtraction = _extractor.UniqueResults
Expand All @@ -201,11 +216,11 @@ private void ImportExportedAddIfPossible(string filePath)
|| Properties.Settings.Default.applyNamePatternOnImportIfEmptyName
|| (!alreadyExists && Properties.Settings.Default.applyNamePatternOnAutoImportForNewCreatures)
);

break;
case ".sav":
case ".json":
alreadyExists = ImportExportGunFiles(new[] { filePath }, out addedToLibrary, out creature);
if (!addedToLibrary || creature == null) return;
if (!addedToLibrary || creature == null) return null;
uniqueExtraction = true;

if (Properties.Settings.Default.applyNamePatternOnAutoImportAlways
Expand All @@ -230,8 +245,10 @@ private void ImportExportedAddIfPossible(string filePath)
}
}

SelectCreatureInLibrary(creature);

break;
default: return;
default: return null;
}

if (creature == null)
Expand Down Expand Up @@ -262,7 +279,7 @@ private void ImportExportedAddIfPossible(string filePath)
&& !FileService.TryCreateDirectory(newPath, out string errorMessage))
{
MessageBoxes.ShowMessageBox($"Subfolder\n{newPath}\ncould not be created.\n{errorMessage}");
return;
return null;
}

string namePattern = Properties.Settings.Default.AutoImportedExportFileRenamePattern;
Expand Down Expand Up @@ -325,6 +342,8 @@ private void ImportExportedAddIfPossible(string filePath)
TopMost = true;
TopMost = false;
}

return addedToLibrary ? creature : null;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/Form1.library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private Creature AddCreatureToCollection(bool fromExtractor = true, long motherA
&& _creatureCollection.DeletedCreatureGuids.Contains(creature.guid))
_creatureCollection.DeletedCreatureGuids.RemoveAll(guid => guid == creature.guid);

_creatureCollection.MergeCreatureList(new List<Creature> { creature });
_creatureCollection.MergeCreatureList(new[] { creature });

// set status of exportedCreatureControl if available
_exportedCreatureControl?.setStatus(importExported.ExportedCreatureControl.ImportStatus.JustImported, DateTime.Now);
Expand Down
Loading

0 comments on commit 3ec4e1b

Please sign in to comment.