Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Sep 16, 2023
2 parents 4fb8cbe + 1ece27a commit 94314de
Show file tree
Hide file tree
Showing 47 changed files with 1,328 additions and 258 deletions.
4 changes: 4 additions & 0 deletions ARKBreedingStats/ARKBreedingStats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<Compile Include="Ark.cs" />
<Compile Include="BreedingPlanning\Score.cs" />
<Compile Include="BreedingPlanning\BreedingScore.cs" />
<Compile Include="importExportGun\ExportGunCreatureFile.cs" />
<Compile Include="importExportGun\ExportGunServerFile.cs" />
<Compile Include="importExportGun\ImportExportGun.cs" />
<Compile Include="importExportGun\ReadExportFile.cs" />
<Compile Include="library\AddDummyCreaturesSettings.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
1 change: 0 additions & 1 deletion ARKBreedingStats/ARKOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public void SetStatLevels(int[] wildValues, int[] tamedValues, int levelWild, in
/// <summary>
/// Used to display longer texts at the top right, e.g. taming-info.
/// </summary>
/// <param name="infoText"></param>
internal void SetInfoText(string infoText, Color textColor)
{
labelInfo.ForeColor = textColor;
Expand Down
22 changes: 22 additions & 0 deletions ARKBreedingStats/Ark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public static class Ark
public const int ColorRegionCount = 6;

#endregion

/// <summary>
/// The name is trimmed to this length in game.
/// </summary>
public const int MaxCreatureNameLength = 24;
}

/// <summary>
Expand All @@ -131,6 +136,23 @@ public static class Stats
public const int TemperatureFortitude = 10;
public const int CraftingSpeedMultiplier = 11;

/// <summary>
/// Index of additive taming multiplier in stat multipliers.
/// </summary>
public const int IndexTamingAdd = 0;
/// <summary>
/// Index of multiplicative taming multiplier in stat multipliers.
/// </summary>
public const int IndexTamingMult = 1;
/// <summary>
/// Index of domesticated level multiplier in stat multipliers.
/// </summary>
public const int IndexLevelDom = 2;
/// <summary>
/// Index of wild level multiplier in stat multipliers.
/// </summary>
public const int IndexLevelWild = 3;

/// <summary>
/// Returns the stat-index for the given order index (like it is ordered in game).
/// </summary>
Expand Down
14 changes: 11 additions & 3 deletions ARKBreedingStats/CreatureInfoInput.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Windows.Forms;
using System.Windows.Threading;
using ARKBreedingStats.Library;
Expand Down Expand Up @@ -47,6 +48,7 @@ public partial class CreatureInfoInput : UserControl
private bool _isNewCreature;

private readonly Debouncer _parentsChangedDebouncer = new Debouncer();
private readonly Debouncer _nameChangedDebouncer = new Debouncer();

/// <summary>
/// The pictureBox that displays the colored species dependent on the selected region colors.
Expand Down Expand Up @@ -589,9 +591,8 @@ public void GenerateCreatureName(Creature creature, int[] speciesTopLevels, int[
{
SetCreatureData(creature);
CreatureName = NamePattern.GenerateCreatureName(creature, _sameSpecies, speciesTopLevels, speciesLowestLevels, customReplacings, showDuplicateNameWarning, namingPatternIndex, false, colorsExisting: ColorAlreadyExistingInformation);
const int maxNameLengthInGame = 24;
if (CreatureName.Length > maxNameLengthInGame)
SetMessageLabelText?.Invoke($"The generated name is longer than {maxNameLengthInGame} characters, the name will look like this in game:\r\n" + CreatureName.Substring(0, maxNameLengthInGame), MessageBoxIcon.Error);
if (CreatureName.Length > Ark.MaxCreatureNameLength)
SetMessageLabelText?.Invoke($"The generated name is longer than {Ark.MaxCreatureNameLength} characters, the name will look like this in game:\r\n" + CreatureName.Substring(0, Ark.MaxCreatureNameLength), MessageBoxIcon.Error);
else SetMessageLabelText?.Invoke();
}

Expand Down Expand Up @@ -754,15 +755,22 @@ private void lblTribe_Click(object sender, EventArgs e)
}

private void textBoxName_TextChanged(object sender, EventArgs e)
{
_nameChangedDebouncer.Debounce(500, CheckIfNameAlreadyExists, Dispatcher.CurrentDispatcher);
}

private void CheckIfNameAlreadyExists()
{
// feedback if name already exists
if (!string.IsNullOrEmpty(textBoxName.Text) && NamesOfAllCreatures != null && NamesOfAllCreatures.Contains(textBoxName.Text))
{
textBoxName.BackColor = Color.Khaki;
_tt.SetToolTip(textBoxName, Loc.S("nameAlreadyExistsInLibrary"));
}
else
{
textBoxName.BackColor = SystemColors.Window;
_tt.SetToolTip(textBoxName, null);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static bool TryCreateDirectory(string path, out string error)
/// <returns>True if the file is not existing after this method ends.</returns>
public static bool TryDeleteFile(string filePath)
{
if (!File.Exists(filePath)) return true;
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) return true;
try
{
File.Delete(filePath);
Expand Down
28 changes: 14 additions & 14 deletions ARKBreedingStats/Form1.Designer.cs

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

103 changes: 103 additions & 0 deletions ARKBreedingStats/Form1.collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Threading;
using System.Windows.Forms;
using System.Xml.Serialization;
using ARKBreedingStats.importExportGun;
using ARKBreedingStats.uiControls;
using ARKBreedingStats.utils;

Expand Down Expand Up @@ -670,6 +671,9 @@ private void SaveDebugFile()
SetMessageLabelText("A File with the current library and the values in the extractor has been created and copied to the clipboard. You can paste this file to a folder to add it to an issue report.", MessageBoxIcon.Information, tempZipFilePath);
}

/// <summary>
/// Zipped library files are often error reports.
/// </summary>
private bool OpenZippedLibrary(string filePath)
{
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
Expand Down Expand Up @@ -768,5 +772,104 @@ private void OpenRecentlyUsedFile(object sender, EventArgs e)
)
LoadCollectionFile(mi.Text);
}

/// <summary>
/// Imports creature from file created by the export gun mod.
/// Returns true if the last imported creature already exists in the library.
/// </summary>
private bool ImportExportGunFiles(string[] filePaths, out bool creatureAdded, out Creature lastAddedCreature)
{
creatureAdded = false;
var newCreatures = new List<Creature>();

var importedCounter = 0;
var importFailedCounter = 0;
string lastError = null;
string lastCreatureFilePath = null;
string serverMultipliersHash = null;
bool? multipliersImportSuccessful = null;
string serverImportResult = null;
bool creatureAlreadyExists = false;

foreach (var filePath in filePaths)
{
var c = ImportExportGun.ImportCreature(filePath, out lastError, out serverMultipliersHash);
if (c != null)
{
newCreatures.Add(c);
importedCounter++;
lastCreatureFilePath = filePath;
}
else if (lastError != null)
{
// file could be a server multiplier file, try to read it that way
var esm = ImportExportGun.ReadServerMultipliers(filePath, out var serverImportResultTemp);
if (esm != null)
{
multipliersImportSuccessful = ImportExportGun.SetServerMultipliers(_creatureCollection, esm, Path.GetFileNameWithoutExtension(filePath));
serverImportResult = serverImportResultTemp;
continue;
}

importFailedCounter++;
MessageBoxes.ShowMessageBox(lastError);
}
}

if (!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");
multipliersImportSuccessful = ImportExportGun.ImportServerMultipliers(_creatureCollection, serverMultiplierFilePath, serverMultipliersHash, out serverImportResult);
}

lastAddedCreature = newCreatures.LastOrDefault();
if (lastAddedCreature != null)
{
creatureAlreadyExists = IsCreatureAlreadyInLibrary(lastAddedCreature.guid, lastAddedCreature.ArkId, out _);
creatureAdded = true;
}

_creatureCollection.MergeCreatureList(newCreatures, true);
UpdateCreatureParentLinkingSort();

var resultText = (importedCounter > 0 || importFailedCounter > 0
? $"Imported {importedCounter} creatures successfully.{(importFailedCounter > 0 ? $"Failed to import {importFailedCounter} files. Last error:{Environment.NewLine}{lastError}" : $"{Environment.NewLine}Last file: {lastCreatureFilePath}")}"
: string.Empty)
+ (string.IsNullOrEmpty(serverImportResult)
? string.Empty
: (importedCounter > 0 || importFailedCounter > 0 ? Environment.NewLine : string.Empty)
+ serverImportResult);

SetMessageLabelText(resultText, importFailedCounter > 0 || multipliersImportSuccessful == false ? MessageBoxIcon.Error : MessageBoxIcon.Information, lastCreatureFilePath);
return creatureAlreadyExists;
}

/// <summary>
/// Call after creatures were added (imported) to the library. Updates parent linkings, creature lists, set collection as changed
/// </summary>
private void UpdateCreatureParentLinkingSort()
{
UpdateParents(_creatureCollection.creatures);

foreach (var creature in _creatureCollection.creatures)
{
creature.RecalculateAncestorGenerations();
}

UpdateIncubationParents(_creatureCollection);

// update UI
SetCollectionChanged(true);
UpdateCreatureListings();

if (_creatureCollection.creatures.Any())
tabControlMain.SelectedTab = tabPageLibrary;

// reapply last sorting
SortLibrary();

UpdateTempCreatureDropDown();
}
}
}
Loading

0 comments on commit 94314de

Please sign in to comment.