Add persistent rand settings

save to xml with version name
This commit is contained in:
Kurt
2018-11-24 23:50:40 -08:00
parent 13ff6099cd
commit 11e5bdbb88
10 changed files with 95 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using pkNX.Structures;
namespace pkNX.Randomization
@@ -6,6 +7,7 @@ namespace pkNX.Randomization
/// <summary>
/// Randomization settings when randomizing a <see cref="PersonalInfo"/>.
/// </summary>
[Serializable]
public class PersonalRandSettings : RandSettings
{
private const string Moves = nameof(Moves);

View File

@@ -1,7 +1,9 @@
using System;
using System.ComponentModel;
namespace pkNX.Randomization
{
[Serializable]
public class LearnSettings
{
private const string General = nameof(General);
@@ -9,11 +11,13 @@ public class LearnSettings
[Category(General), Description("Expands the learnset to the specified count.")]
public bool Expand { get; set; } = true;
[Category(General), Description("Count to expand the learnset to.")]
public int ExpandTo { get; set; } = 25;
[Category(General), Description("Evenly spreads learned moves out from level 1 to the specified end level.")]
public bool Spread { get; set; } = true;
[Category(General), Description("Level to end learning level up moves.")]
public int SpreadTo { get; set; } = 75;

View File

@@ -4,6 +4,7 @@
namespace pkNX.Randomization
{
[Serializable]
public class MovesetRandSettings
{
private const string Damage = nameof(Damage);

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using pkNX.Structures;
@@ -8,6 +9,7 @@ namespace pkNX.Randomization
/// <summary>
/// Settings for what Species are permitted during randomization.
/// </summary>
[Serializable]
public class SpeciesSettings : RandSettings
{
private const string General = nameof(General);

View File

@@ -1,7 +1,9 @@
using System;
using System.ComponentModel;
namespace pkNX.Randomization
{
[Serializable]
public class TrainerRandSettings
{
private const string General = nameof(General);

View File

@@ -67,6 +67,7 @@ private void Main_FormClosing(object sender, FormClosingEventArgs e)
return;
Editor.Close();
EditUtil.SaveSettings(Editor.Game);
Settings.Default.Language = CB_Lang.SelectedIndex;
Settings.Default.GamePath = TB_Path.Text;
Settings.Default.Save();
@@ -133,6 +134,8 @@ private void LoadROM(EditorBase editor)
Text = $"{nameof(pkNX)} - {Editor.Game}";
TB_Path.Text = Editor.Location;
EditUtil.LoadSettings(Editor.Game);
EditUtil.SaveSettings(Editor.Game);
System.Media.SystemSounds.Asterisk.Play();
}
}

View File

@@ -1,13 +1,75 @@
using pkNX.Randomization;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;
using pkNX.Randomization;
using pkNX.Structures;
namespace pkNX.WinForms
{
[Serializable]
public class SharedSettings
{
public PersonalRandSettings Personal { get; set; } = new PersonalRandSettings();
public SpeciesSettings Species { get; set; } = new SpeciesSettings();
public TrainerRandSettings Trainer { get; set; } = new TrainerRandSettings();
public MovesetRandSettings Move { get; set; } = new MovesetRandSettings();
public LearnSettings Learn { get; set; } = new LearnSettings();
}
public static class EditUtil
{
public static PersonalRandSettings Personal { get; set; } = new PersonalRandSettings();
public static SpeciesSettings Species { get; set; } = new SpeciesSettings();
public static TrainerRandSettings Trainer { get; set; } = new TrainerRandSettings();
public static MovesetRandSettings Move { get; set; } = new MovesetRandSettings();
public static LearnSettings Learn { get; set; } = new LearnSettings();
public static SharedSettings Settings { get; set; }
public static void LoadSettings(GameVersion game)
{
string path = GetSettingsFileName(game);
if (!File.Exists(path))
{
Settings = new SharedSettings();
return;
}
using (var file = File.OpenRead(path))
{
var reader = new XmlSerializer(typeof(SharedSettings));
try
{
Settings = (SharedSettings) reader.Deserialize(file);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
}
public static void SaveSettings(GameVersion game)
{
string path = GetSettingsFileName(game);
using (var file = File.Create(path))
{
var writer = new XmlSerializer(typeof(SharedSettings));
try
{
writer.Serialize(file, Settings);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
if (!File.Exists(path))
return;
file.Close();
File.Delete(path);
}
}
}
private static string GetSettingsFileName(GameVersion game)
{
var path = Path.GetDirectoryName(Application.ExecutablePath);
return Path.Combine(path, $"randsetting{game}.xml");
}
}
}

View File

@@ -67,9 +67,9 @@ public BTTE(GameManager game, TrainerEditor editor)
CB_TrainerID.SelectedIndex = 0;
PG_Moves.SelectedObject = EditUtil.Move;
PG_RTrainer.SelectedObject = EditUtil.Trainer;
PG_Species.SelectedObject = EditUtil.Species;
PG_Moves.SelectedObject = EditUtil.Settings.Move;
PG_RTrainer.SelectedObject = EditUtil.Settings.Trainer;
PG_Species.SelectedObject = EditUtil.Settings.Species;
}
public bool Modified { get; set; }

View File

@@ -40,7 +40,7 @@ public GGWE(GameManager rom, string json)
EL_Old.OverworldSpawn = EL_Good.OverworldSpawn = EL_Super.OverworldSpawn = false;
L_Rank.Visible = NUD_RankMin.Visible = NUD_RankMax.Visible = false;
PG_Species.SelectedObject = EditUtil.Species;
PG_Species.SelectedObject = EditUtil.Settings.Species;
Tables = obj;
LoadFile(locs);
@@ -334,6 +334,7 @@ private void B_RandAll_Click(object sender, EventArgs e)
{
SaveEntry(entry);
var settings = (SpeciesSettings)PG_Species.SelectedObject;
settings.Gen2 = settings.Gen3 = settings.Gen4 = settings.Gen5 = settings.Gen6 = settings.Gen7 = false;
var rand = new SpeciesRandomizer(ROM.Info, ROM.Data.PersonalData);
rand.Initialize(settings);
RandomizeWild(rand, CHK_FillEmpty.Checked, CHK_WildMega.Checked);

View File

@@ -50,9 +50,9 @@ public PokeDataUI(PokeEditor editor, GameManager rom)
CB_Species.SelectedIndex = 1;
PG_Personal.SelectedObject = EditUtil.Personal;
PG_Evolution.SelectedObject = EditUtil.Species;
PG_Learn.SelectedObject = EditUtil.Learn;
PG_Personal.SelectedObject = EditUtil.Settings.Personal;
PG_Evolution.SelectedObject = EditUtil.Settings.Species;
PG_Learn.SelectedObject = EditUtil.Settings.Learn;
}
public GameManager ROM { get; set; }
@@ -474,7 +474,7 @@ private void B_RandLearn_Click(object sender, EventArgs e)
var rand = new LearnsetRandomizer(ROM.Info, Editor.Learn.LoadAll(), Editor.Personal);
var moves = ROM.Data.MoveData.LoadAll();
int[] banned = Legal.GetBannedMoves(ROM.Info.Game, moves);
rand.Initialize(moves, settings, EditUtil.Move, banned);
rand.Initialize(moves, settings, EditUtil.Settings.Move, banned);
rand.Execute();
LoadIndex(CB_Species.SelectedIndex);
System.Media.SystemSounds.Asterisk.Play();
@@ -490,7 +490,7 @@ private void B_LearnExpand_Click(object sender, EventArgs e)
return;
}
var rand = new LearnsetRandomizer(ROM.Info, Editor.Learn.LoadAll(), Editor.Personal);
rand.Initialize(ROM.Data.MoveData.LoadAll(), settings, EditUtil.Move);
rand.Initialize(ROM.Data.MoveData.LoadAll(), settings, EditUtil.Settings.Move);
rand.ExecuteExpandOnly();
LoadIndex(CB_Species.SelectedIndex);
System.Media.SystemSounds.Asterisk.Play();
@@ -500,7 +500,7 @@ private void B_LearnMetronome_Click(object sender, EventArgs e)
{
var settings = (LearnSettings)PG_Learn.SelectedObject;
var rand = new LearnsetRandomizer(ROM.Info, Editor.Learn.LoadAll(), Editor.Personal);
rand.Initialize(ROM.Data.MoveData.LoadAll(), settings, EditUtil.Move);
rand.Initialize(ROM.Data.MoveData.LoadAll(), settings, EditUtil.Settings.Move);
rand.ExecuteMetronome();
LoadIndex(CB_Species.SelectedIndex);
System.Media.SystemSounds.Asterisk.Play();