public void TestConfigCloning() { var original = new RandomizerConfig(); // Change everything from the default void ChangeProps(object obj) { foreach (var prop in obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { var value = prop.GetValue(obj); switch (value) { case bool b: prop.SetValue(obj, !b); break; case decimal d: prop.SetValue(obj, d + 0.1m); break; case var o when !value.GetType().IsPrimitive: ChangeProps(o); break; } } } ChangeProps(original); var cloned = original.AsEditable(); Assert.AreNotSame(original, cloned, "Cloned config should not be the same instance as the source!"); AssertEx.DeepPropertiesAreEqual(original, cloned, "Clone config's properties were not equal to source!"); }
public MainWindow(Language gameLanguage, string gameDirectory) { this.InitializeComponent(); this.gameLanguage = gameLanguage; this.gameDirectory = gameDirectory; this.config = new RandomizerConfig(); }
public async Task LoadRandomizer() { this.SetUpOutputDirectory(); Game = new GameConfig(GameVersion.XY); string romPath = Path.GetFullPath(Settings.RomPathXy); string romFsPath = Path.Combine(romPath, "RomFS"); string exeFsPath = Path.Combine(romPath, "ExeFS"); Assert.True(Directory.Exists(romPath), "ROM path does not exist"); Assert.True(Directory.Exists(romFsPath), "ROM path does not contain a RomFS folder"); Assert.True(Directory.Exists(exeFsPath), "ROM path does not contain an ExeFS folder"); await Game.Initialize(romPath, Language.English); RandomizerConfig randConfig = new RandomizerConfig { EggMoves = { }, Encounters = { LevelMultiplier = 1.25m, TypeThemedAreas = true }, Learnsets = { AtLeast4Moves = true, RandomizeLevels = true }, OverworldItems = { }, PokemonInfo = { }, Starters = { StartersOnly = false }, Trainers = { FriendKeepsStarter = true, LevelMultiplier = 1.3m, TypeThemed = true } }; Randomizer = PokeRandomizer.Common.Randomizer.GetRandomizer(Game, randConfig); Game.OutputPathOverride = this.romOutputDir; Assert.NotNull(Randomizer); this.masterRandom = new Random(Randomizer.RandomSeed); }
public static IRandomizer GetRandomizer(GameConfig game, RandomizerConfig config, int?seed = null) { var randomizers = from asm in AppDomain.CurrentDomain.GetAssemblies() from type in asm.GetTypes() where typeof(BaseRandomizer).IsAssignableFrom(type) let attrs = type.GetCustomAttributes <HandlesGameAttribute>() where attrs.Any() select(type, attrs); foreach (var(type, attrs) in randomizers) { if (attrs.Any(attr => attr.GameVersion == game.Version)) { object objInstance; if (seed == null) { objInstance = Activator.CreateInstance(type); } else { objInstance = Activator.CreateInstance(type, seed); } if (!(objInstance is BaseRandomizer instance)) { throw new ApplicationException($"Could not create instance of {type.Name} as a BaseRandomizer"); } instance.Initialize(game, config); return(instance); } } throw new NotSupportedException($"There is no loaded randomizer which supports the game version {game.Version}"); }
protected override void LoadDefaultConfig() { config = new RandomizerConfig { EnableDefaultSkin = true, EnablePermissions = false }; }
protected override void LoadConfig() { base.LoadConfig(); config = Config.ReadObject <RandomizerConfig>(); }
public static void SetConfig(RandomizerPage page, RandomizerConfig value) => page.SetValue(ConfigProperty, value);
internal void Initialize(GameConfig game, RandomizerConfig randomizerConfig) { this.Game = game; this.Config = randomizerConfig; }
public async Task LoadRandomizer() { this.SetUpOutputDirectory(); Game = new GameConfig(GameVersion.ORAS); string romPath = Path.GetFullPath(Settings.RomPathOras); string romFsPath = Path.Combine(romPath, "RomFS"); string exeFsPath = Path.Combine(romPath, "ExeFS"); Assert.True(Directory.Exists(romPath), "ROM path does not exist"); Assert.True(Directory.Exists(romFsPath), "ROM path does not contain a RomFS folder"); Assert.True(Directory.Exists(exeFsPath), "ROM path does not contain an ExeFS folder"); await Game.Initialize(romPath, Language.English); RandomizerConfig randConfig = new RandomizerConfig { EggMoves = { RandomizeEggMoves = true, FavorSameType = true, }, Encounters = { RandomizeEncounters = true, LevelMultiplier = 1.25m, TypeThemedAreas = true, AllowLegendaries = true, }, Learnsets = { RandomizeLearnsets = true, AtLeast4Moves = true, RandomizeLevels = true, FavorSameType = true, }, OverworldItems = { RandomizeOverworldItems = true, AllowMegaStones = true, RandomizeTMs = true, AllowMasterBalls = true, }, PokemonInfo = { RandomizeTypes = true, RandomizePrimaryTypes = true, RandomizeSecondaryTypes = true, RandomizeAbilities = true, }, Starters = { RandomizeStarters = true, StartersOnly = false, AllowLegendaries = true, }, Trainers = { RandomizeTrainers = true, FriendKeepsStarter = true, LevelMultiplier = 1.3m, TypeThemed = true, TypeThemedGyms = true, } }; Randomizer = PokeRandomizer.Common.Randomizer.GetRandomizer(Game, randConfig) as Gen6Randomizer; Game.OutputPathOverride = this.romOutputDir; Assert.NotNull(Randomizer); this.masterRandom = new Random(Randomizer.RandomSeed); }
public ConfigTests() { this.config = new RandomizerConfig(); }