Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings rearrange & added config paths #1238

Merged
merged 1 commit into from
Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions PoGo.NecroBot.Logic/Common/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using PoGo.NecroBot.Logic.State;

#endregion

Expand Down Expand Up @@ -235,13 +236,11 @@ public string GetTranslation(TranslationString translationString)
var translation = TranslationStrings.FirstOrDefault(t => t.Key.Equals(translationString)).Value;
return translation != default(string) ? translation : $"Translation for {translationString} is missing";
}

public static Translation Load(string translationsLanguageCode)
public static Translation Load(ILogicSettings logicSettings)
{
string profilePath = Directory.GetCurrentDirectory();
string configPath = Path.Combine(profilePath, "config", "translations");

var fullPath = Path.Combine(configPath, "translation." + translationsLanguageCode + ".json");
string translationsLanguageCode = logicSettings.TranslationLanguageCode;
var translationPath = Path.Combine(logicSettings.GeneralConfigPath, "translations");
var fullPath = Path.Combine(translationPath, "translation." + translationsLanguageCode + ".json");

Translation translations;
if (File.Exists(fullPath))
Expand All @@ -259,7 +258,7 @@ public static Translation Load(string translationsLanguageCode)
else
{
translations = new Translation();
translations.Save(Path.Combine(configPath, "translation.en.json"));
translations.Save(Path.Combine(translationPath, "translation.en.json"));
}
return translations;
}
Expand Down
3 changes: 2 additions & 1 deletion PoGo.NecroBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public interface ILogicSettings
int AmountOfPokemonToDisplayOnStart { get; }
string TranslationLanguageCode { get; }
string ProfilePath { get; }
string ConfigPath { get; }
string ProfileConfigPath { get; }
string GeneralConfigPath { get; }

ICollection<KeyValuePair<ItemId, int>> ItemRecycleFilter { get; }

Expand Down
68 changes: 34 additions & 34 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,37 @@ public class GlobalSettings
public int AmountOfPokemonToDisplayOnStart = 10;

[JsonIgnore] internal AuthSettings Auth = new AuthSettings();
[JsonIgnore] public string ProfilePath;
[JsonIgnore] public string ProfileConfigPath;
[JsonIgnore] public string GeneralConfigPath;

public bool AutoUpdate = true;
public string ConfigPath;
public double DefaultAltitude = 10;
public double DefaultLatitude = 40.785091;
public double DefaultLongitude = -73.968285;
public int DelayBetweenPokemonCatch = 2000;
public float EvolveAboveIvValue = 90;
public bool EvolveAllPokemonAboveIv = false;
public bool EvolveAllPokemonWithEnoughCandy = true;
public int UseLuckyEggsMinPokemonAmount = 30;
public bool UseLuckyEggsWhileEvolving = false;
public bool UseEggIncubators = true;
public bool DumpPokemonStats = false;
public string GpxFile = "GPXPath.GPX";
public bool UseGpxPathing = false;
public double WalkingSpeedInKilometerPerHour = 15.0;
public int MaxTravelDistanceInMeters = 1000;
public int KeepMinCp = 1250;
public int KeepMinDuplicatePokemon = 1;
public float KeepMinIvPercentage = 95;
public bool KeepPokemonsThatCanEvolve = false;
public bool PrioritizeIvOverCp = true;
public bool RenameAboveIv = true;
public bool TransferDuplicatePokemon = true;
public string TranslationLanguageCode = "en";
public bool UsePokemonToNotCatchFilter = false;
public int WebSocketPort = 14251;
public bool StartupWelcomeDelay = true;

public List<KeyValuePair<ItemId, int>> ItemRecycleFilter = new List<KeyValuePair<ItemId, int>>
{
Expand Down Expand Up @@ -147,14 +166,9 @@ public class GlobalSettings
new KeyValuePair<ItemId, int>(ItemId.ItemItemStorageUpgrade, 100)
};

public int KeepMinCp = 1250;
public int KeepMinDuplicatePokemon = 1;
public float KeepMinIvPercentage = 95;
public bool KeepPokemonsThatCanEvolve = false;
public int MaxTravelDistanceInMeters = 1000;

public List<PokemonId> PokemonsNotToTransfer = new List<PokemonId>
{
PokemonId.Aerodactyl,
PokemonId.Venusaur,
PokemonId.Charizard,
PokemonId.Blastoise,
Expand Down Expand Up @@ -243,33 +257,19 @@ public class GlobalSettings
{PokemonId.Eevee, new TransferFilter(600, 90, 2)},
{PokemonId.Mew, new TransferFilter(0, 0, 10)}
};

public bool PrioritizeIvOverCp = true;
public string ProfilePath;
public bool RenameAboveIv = true;
public bool TransferDuplicatePokemon = true;
public string TranslationLanguageCode = "en";
public bool UseEggIncubators = true;
public bool UseGpxPathing = false;
public int UseLuckyEggsMinPokemonAmount = 30;
public bool UseLuckyEggsWhileEvolving = false;
public bool UsePokemonToNotCatchFilter = false;
public double WalkingSpeedInKilometerPerHour = 15.0;
public int WebSocketPort = 14251;
public static GlobalSettings Default => new GlobalSettings();
public bool StartupWelcomeDelay = true;

public static GlobalSettings Load(string path)
{
GlobalSettings settings;
var profilePath = Path.Combine(Directory.GetCurrentDirectory(), path);
var configPath = Path.Combine(profilePath, "config");
var fullPath = Path.Combine(configPath, "config.json");
var profileConfigPath = Path.Combine(profilePath, "config");
var configFile = Path.Combine(profileConfigPath, "config.json");

if (File.Exists(fullPath))
if (File.Exists(configFile))
{
//if the file exists, load the settings
var input = File.ReadAllText(fullPath);
var input = File.ReadAllText(configFile);

var jsonSettings = new JsonSerializerSettings();
jsonSettings.Converters.Add(new StringEnumConverter {CamelCaseText = true});
Expand All @@ -289,17 +289,16 @@ public static GlobalSettings Load(string path)
}

settings.ProfilePath = profilePath;
settings.ConfigPath = configPath;
settings.ProfileConfigPath = profileConfigPath;
settings.GeneralConfigPath = Path.Combine(Directory.GetCurrentDirectory(), "config");

if (!File.Exists(fullPath))
{
settings.Save(fullPath);
return null;
}
var firstRun = !File.Exists(configFile);

settings.Save(configFile);

settings.Save(fullPath);
if (firstRun) return null;

settings.Auth.Load(Path.Combine(configPath, "auth.json"));
settings.Auth.Load(Path.Combine(profileConfigPath, "auth.json"));

return settings;
}
Expand Down Expand Up @@ -456,7 +455,8 @@ public LogicSettings(GlobalSettings settings)
}

public string ProfilePath => _settings.ProfilePath;
public string ConfigPath => _settings.ConfigPath;
public string ProfileConfigPath => _settings.ProfileConfigPath;
public string GeneralConfigPath => _settings.GeneralConfigPath;
public bool AutoUpdate => _settings.AutoUpdate;
public float KeepMinIvPercentage => _settings.KeepMinIvPercentage;
public int KeepMinCp => _settings.KeepMinCp;
Expand Down
2 changes: 1 addition & 1 deletion PoGo.NecroBot.Logic/State/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Session(ISettings settings, ILogicSettings logicSettings)
Settings = settings;
LogicSettings = logicSettings;
EventDispatcher = new EventDispatcher();
Translation = Common.Translation.Load(logicSettings.TranslationLanguageCode);
Translation = Common.Translation.Load(logicSettings);
Reset(settings, LogicSettings);
}

Expand Down