Compare commits
8 Commits
38754f7417
...
9a40c9dc0f
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a40c9dc0f | |||
| 28948fdc80 | |||
| adaeb9f377 | |||
| 101a60415c | |||
| 720cc469d4 | |||
| 96cebd2289 | |||
| e5fd52376e | |||
| f5f8e6a9d0 |
@@ -1,4 +1,5 @@
|
||||
scripts/
|
||||
Dockerfile
|
||||
justfile
|
||||
|
||||
ALttPRandomizer/appsettings.json
|
||||
ALttPRandomizer/appsettings.Development.json
|
||||
@@ -10,4 +11,10 @@ ALttPRandomizer/[Bb]in
|
||||
*/DR_*
|
||||
*/ER_*
|
||||
*/OR_*
|
||||
*/data/base2current.json
|
||||
*/GK_*
|
||||
*.sfc
|
||||
*_Spoiler.txt
|
||||
|
||||
!alttp.sfc
|
||||
|
||||
# */data/base2current.json
|
||||
|
||||
10
.editorconfig
Normal file
10
.editorconfig
Normal file
@@ -0,0 +1,10 @@
|
||||
[*.cs]
|
||||
|
||||
# CA1822: Mark members as static
|
||||
dotnet_diagnostic.CA1822.severity = none
|
||||
|
||||
# IDE0305: Simplify collection initialization
|
||||
dotnet_style_prefer_collection_expression = never
|
||||
|
||||
# IDE0290: Use primary constructor
|
||||
csharp_style_prefer_primary_constructors = false
|
||||
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* text=auto
|
||||
20
.gitmodules
vendored
20
.gitmodules
vendored
@@ -1,12 +1,16 @@
|
||||
[submodule "ALttPDoorRandomizer"]
|
||||
path = ALttPDoorRandomizer
|
||||
url = https://github.com/ardnaxelarak/ALttPDoorRandomizer
|
||||
[submodule "BaseRandomizer"]
|
||||
path = BaseRandomizer
|
||||
url = https://github.com/ardnaxelarak/ALttPDoorRandomizer
|
||||
url = https://git.gwaa.kiwi/alttpr-gwaa-kiwi/alttpr-python
|
||||
branch = main
|
||||
[submodule "Apr2025Randomizer"]
|
||||
path = Apr2025Randomizer
|
||||
url = https://github.com/ardnaxelarak/ALttPDoorRandomizer
|
||||
[submodule "DungeonMapRandomizer"]
|
||||
path = DungeonMapRandomizer
|
||||
url = git@github.com:ardnaxelarak/ALttPDoorRandomizer
|
||||
url = https://git.gwaa.kiwi/alttpr-gwaa-kiwi/alttpr-python
|
||||
branch = apr_2025
|
||||
[submodule "BetaRandomizer"]
|
||||
path = BetaRandomizer
|
||||
url = https://git.gwaa.kiwi/alttpr-gwaa-kiwi/alttpr-python
|
||||
branch = beta
|
||||
[submodule "PikitRandomizer"]
|
||||
path = PikitRandomizer
|
||||
url = https://git.gwaa.kiwi/alttpr-gwaa-kiwi/alttpr-python.git
|
||||
branch = pikit
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.12.35521.163 d17.12
|
||||
VisualStudioVersion = 17.12.35521.163
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ALttPRandomizer", "ALttPRandomizer\ALttPRandomizer.csproj", "{8F6F2C3C-ACE4-4944-9722-21E71222195A}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.editorconfig = .editorconfig
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
using System;
|
||||
|
||||
public class GenerationFailedException : Exception {
|
||||
public GenerationFailedException(string message) : base(message) { }
|
||||
public GenerationFailedException(string message, params string[] args) : base(string.Format(message, args)) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public static class JsonOptions {
|
||||
public static JsonSerializerOptions Default = new JsonSerializerOptions(JsonSerializerDefaults.Web) {
|
||||
public static readonly JsonSerializerOptions Default = new JsonSerializerOptions(JsonSerializerDefaults.Web) {
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
||||
NumberHandling = JsonNumberHandling.Strict,
|
||||
}.WithStringEnum();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
public RaceMode Race { get; set; } = RaceMode.Normal;
|
||||
|
||||
[ForbiddenSetting([Apr2025], Mode.Inverted)]
|
||||
[RequiredSetting([Pikit], Mode.Open)]
|
||||
public Mode Mode { get; set; } = Mode.Open;
|
||||
|
||||
[SettingName("swords")]
|
||||
@@ -26,52 +27,57 @@
|
||||
public Goal Goal { get; set; } = Goal.Ganon;
|
||||
|
||||
[SettingName("crystals_ganon")]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public EntryRequirement CrystalsGanon { get; set; } = EntryRequirement.Crystals7;
|
||||
|
||||
[SettingName("bosses_ganon")]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public BossRequirement BossesGanon { get; set; } = BossRequirement.Bosses8of10;
|
||||
|
||||
[NoSettingName]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public TriforceRequirement TriforcePieces { get; set; } = TriforceRequirement.Triforce20of30;
|
||||
|
||||
[SettingName("crystals_gt")]
|
||||
[JsonPropertyName("crystals_gt")]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public EntryRequirement CrystalsGT { get; set; } = EntryRequirement.Crystals7;
|
||||
|
||||
[SettingName("ganon_item")]
|
||||
[RequiredSetting([Apr2025], GanonItem.Silver)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public GanonItem GanonItem { get; set; } = GanonItem.Silver;
|
||||
|
||||
[SettingName("shuffle")]
|
||||
[ForbiddenSetting([Apr2025], EntranceShuffle.Swapped)]
|
||||
public EntranceShuffle EntranceShuffle { get; set; } = EntranceShuffle.Vanilla;
|
||||
|
||||
[SettingName("overworld_map")]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public OverworldMapDungeons OverworldMapDungeons { get; set; } = OverworldMapDungeons.Vanilla;
|
||||
|
||||
[NoSettingName]
|
||||
[RequiredSetting([Apr2025], LinksHouse.Vanilla)]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public LinksHouse LinksHouse { get; set; } = LinksHouse.Vanilla;
|
||||
|
||||
[SettingName("skullwoods")]
|
||||
[RequiredSetting([Apr2025], SkullWoodsShuffle.Original)]
|
||||
[NoSettingName([Apr2025])]
|
||||
public SkullWoodsShuffle SkullWoods { get; set; } = SkullWoodsShuffle.Original;
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public SkullWoodsShuffle SkullWoods { get; set; } = SkullWoodsShuffle.Default;
|
||||
|
||||
[SettingName("linked_drops")]
|
||||
[RequiredSetting([Apr2025], LinkedDrops.Unset)]
|
||||
[NoSettingName([Apr2025])]
|
||||
public LinkedDrops LinkedDrops { get; set; } = LinkedDrops.Unset;
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public LinkedDrops LinkedDrops { get; set; } = LinkedDrops.Default;
|
||||
|
||||
[SettingName("shufflebosses")]
|
||||
[RequiredSetting([Apr2025], BossShuffle.Vanilla)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public BossShuffle BossShuffle { get; set; } = BossShuffle.Vanilla;
|
||||
|
||||
[SettingName("shuffleenemies")]
|
||||
[RequiredSetting([Apr2025], EnemyShuffle.Vanilla)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
[RequiredSetting([Pikit], EnemyShuffle.Vanilla)]
|
||||
public EnemyShuffle EnemyShuffle { get; set; } = EnemyShuffle.Vanilla;
|
||||
|
||||
[SettingName("shuffle_damage_table")]
|
||||
[RequiredSetting([Apr2025], DamageTableShuffle.Vanilla)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DamageTableShuffle DamageTableShuffle { get; set; } = DamageTableShuffle.Vanilla;
|
||||
|
||||
[SettingName("keyshuffle")]
|
||||
@@ -80,44 +86,38 @@
|
||||
public KeyLocations SmallKeys { get; set; } = KeyLocations.Dungeon;
|
||||
|
||||
[SettingName("bigkeyshuffle")]
|
||||
[RequiredSetting([Apr2025], DungeonItemLocations.Dungeon)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DungeonItemLocations BigKeys { get; set; } = DungeonItemLocations.Dungeon;
|
||||
|
||||
[SettingName("mapshuffle")]
|
||||
[RequiredSetting([Apr2025], DungeonItemLocations.Dungeon)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DungeonItemLocations Maps { get; set; } = DungeonItemLocations.Dungeon;
|
||||
|
||||
[SettingName("compassshuffle")]
|
||||
[RequiredSetting([Apr2025], DungeonItemLocations.Dungeon)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DungeonItemLocations Compasses { get; set; } = DungeonItemLocations.Dungeon;
|
||||
|
||||
[SettingName("showloot")]
|
||||
[RequiredSetting([Apr2025, Base], ShowLoot.Never)]
|
||||
[NoSettingName([Apr2025, Base])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public ShowLoot ShowLoot { get; set; } = ShowLoot.Never;
|
||||
|
||||
[SettingName("showmap")]
|
||||
[RequiredSetting([Apr2025, Base], ShowMap.Map)]
|
||||
[NoSettingName([Apr2025, Base])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public ShowMap ShowMap { get; set; } = ShowMap.Map;
|
||||
|
||||
[NoSettingName]
|
||||
[RequiredSetting([Apr2025], ShopShuffle.Vanilla)]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public ShopShuffle ShopShuffle { get; set; } = ShopShuffle.Vanilla;
|
||||
|
||||
[RequiredSetting([Apr2025], DropShuffle.Vanilla)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DropShuffle DropShuffle { get; set; } = DropShuffle.Vanilla;
|
||||
|
||||
[RequiredSetting([Apr2025], Pottery.Vanilla)]
|
||||
[NoSettingName([Apr2025])]
|
||||
public Pottery Pottery { get; set; } = Pottery.Vanilla;
|
||||
[SettingName("pottery")]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public PotShuffle PotShuffle { get; set; } = PotShuffle.Vanilla;
|
||||
|
||||
[RequiredSetting([Apr2025], PrizeShuffle.Vanilla)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
[RequiredSetting([Pikit], PrizeShuffle.Vanilla)]
|
||||
public PrizeShuffle PrizeShuffle { get; set; } = PrizeShuffle.Vanilla;
|
||||
|
||||
[NoSettingName]
|
||||
@@ -125,68 +125,86 @@
|
||||
public BootsSettings Boots { get; set; } = BootsSettings.Normal;
|
||||
|
||||
[NoSettingName]
|
||||
[RequiredSetting([Apr2025], FluteSettings.Normal)]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public FluteSettings Flute { get; set; } = FluteSettings.Normal;
|
||||
|
||||
[SettingName("dark_rooms")]
|
||||
[RequiredSetting([Apr2025], DarkRoomSettings.RequireLamp)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DarkRoomSettings DarkRooms { get; set; } = DarkRoomSettings.RequireLamp;
|
||||
|
||||
[NoSettingName]
|
||||
[RequiredSetting([Apr2025], BombSettings.Normal)]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public BombSettings Bombs { get; set; } = BombSettings.Normal;
|
||||
|
||||
[NoSettingName]
|
||||
[RequiredSetting([Apr2025], BookSettings.Normal)]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public BookSettings Book { get; set; } = BookSettings.Normal;
|
||||
|
||||
[NoSettingName]
|
||||
[RequiredSetting([Apr2025], MirrorSettings.Normal)]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public MirrorSettings Mirror { get; set; } = MirrorSettings.Normal;
|
||||
|
||||
[SettingName("door_shuffle")]
|
||||
[RequiredSetting([Apr2025], DoorShuffle.Vanilla)]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DoorShuffle DoorShuffle { get; set; } = DoorShuffle.Vanilla;
|
||||
|
||||
[SettingName("intensity")]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DoorLobbies Lobbies { get; set; } = DoorLobbies.Vanilla;
|
||||
|
||||
[SettingName("door_type_mode")]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DoorTypeMode DoorTypeMode { get; set; } = DoorTypeMode.Big;
|
||||
|
||||
[SettingName("trap_door_mode")]
|
||||
[NoSettingName([Apr2025])]
|
||||
public TrapDoorMode TrapDoorMode { get; set; } = TrapDoorMode.Optional;
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public TrapDoorMode TrapDoorMode { get; set; } = TrapDoorMode.Some;
|
||||
|
||||
[NoSettingName]
|
||||
[RequiredSetting([Apr2025], FollowerShuffle.Vanilla)]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public FollowerShuffle FollowerShuffle { get; set; } = FollowerShuffle.Vanilla;
|
||||
|
||||
[SettingName("ow_fluteshuffle")]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public FluteShuffle FluteShuffle { get; set; } = FluteShuffle.Vanilla;
|
||||
|
||||
[SettingName("ow_layout")]
|
||||
[IgnoreSetting(Apr2025, Base)]
|
||||
public OverworldLayout OverworldLayout { get; set; } = OverworldLayout.Vanilla;
|
||||
|
||||
[NoSettingName]
|
||||
[RequiredSetting([Apr2025], TileSwap.Vanilla)]
|
||||
[IgnoreSetting(Apr2025, Base)]
|
||||
public OverworldWorldLayouts OverworldWorldLayouts { get; set; } = OverworldWorldLayouts.Parallel;
|
||||
|
||||
[NoSettingName]
|
||||
[IgnoreSetting(Apr2025, Base)]
|
||||
public OverworldLayoutTerrain OverworldLayoutTerrain { get; set; } = OverworldLayoutTerrain.SameOnly;
|
||||
|
||||
[NoSettingName]
|
||||
[IgnoreSetting(Apr2025, Base)]
|
||||
public OverworldLayoutEdges OverworldLayoutEdges { get; set; } = OverworldLayoutEdges.Unrestricted;
|
||||
|
||||
[NoSettingName]
|
||||
[IgnoreSetting(Apr2025, Base)]
|
||||
public OverworldMapFog OverworldMapFog { get; set; } = OverworldMapFog.Fog;
|
||||
|
||||
[NoSettingName]
|
||||
[IgnoreSetting(Apr2025, Pikit)]
|
||||
public TileSwap TileSwap { get; set; } = TileSwap.Vanilla;
|
||||
|
||||
[SettingName("damage_challenge")]
|
||||
[NoSettingName([Apr2025])]
|
||||
[IgnoreSetting(Apr2025)]
|
||||
public DamageChallengeMode DamageChallenge { get; set; } = DamageChallengeMode.Normal;
|
||||
|
||||
[NoSettingName]
|
||||
public Hints Hints { get; set; } = Hints.Off;
|
||||
}
|
||||
|
||||
public enum RandomizerInstance
|
||||
{
|
||||
[RandomizerName(BaseRandomizer.Name)] Base,
|
||||
[RandomizerName(Apr2025Randomizer.Name)] Apr2025,
|
||||
[RandomizerName(BaseRandomizer.DungeonMapName)] DungeonMap,
|
||||
public enum RandomizerInstance {
|
||||
[GeneratorSettings("base", "GK_", "--bps", "--spoiler=json")] Base,
|
||||
[GeneratorSettings("beta", "GK_", "--bps", "--spoiler=json")] Beta,
|
||||
[GeneratorSettings("pikit", "GK_", "--bps", "--spoiler=json")] Pikit,
|
||||
[GeneratorSettings("apr2025", "ER_", requireFlips: true, "--json_spoiler")] Apr2025,
|
||||
}
|
||||
|
||||
public enum RaceMode {
|
||||
@@ -233,6 +251,14 @@
|
||||
Random,
|
||||
}
|
||||
|
||||
public enum TriforceRequirement {
|
||||
[JsonStringEnumMemberName("8of10")] [AdditionalSetting("--triforce_goal=8", "--triforce_pool=10")] Triforce8of10,
|
||||
[JsonStringEnumMemberName("20of30")] [AdditionalSetting("--triforce_goal=20", "--triforce_pool=30")] Triforce20of30,
|
||||
[JsonStringEnumMemberName("67of100")] [AdditionalSetting("--triforce_goal=67", "--triforce_pool=100")] Triforce67of100,
|
||||
[JsonStringEnumMemberName("125of175")] [AdditionalSetting("--triforce_goal=125", "--triforce_pool=175")] Triforce125of175,
|
||||
[JsonStringEnumMemberName("400of500")] [AdditionalSetting("--triforce_goal=400", "--triforce_pool=500")] Triforce400of500,
|
||||
}
|
||||
|
||||
public enum BossRequirement {
|
||||
[JsonStringEnumMemberName("0of10")] [SettingName("0")] Bosses0of10,
|
||||
[JsonStringEnumMemberName("1of10")] [SettingName("1")] Bosses1of10,
|
||||
@@ -287,20 +313,26 @@
|
||||
[SettingName("insanity")] Decoupled,
|
||||
}
|
||||
|
||||
public enum OverworldMapDungeons {
|
||||
[SettingName("default")] Vanilla,
|
||||
Compass,
|
||||
Map,
|
||||
}
|
||||
|
||||
public enum LinksHouse {
|
||||
Vanilla,
|
||||
[AdditionalSetting("--shufflelinks")] Shuffled,
|
||||
}
|
||||
|
||||
public enum SkullWoodsShuffle {
|
||||
Original,
|
||||
Restricted,
|
||||
[SettingName("original")] Default,
|
||||
[SettingName("restricted")] VanillaDrops,
|
||||
Loose,
|
||||
FollowLinked,
|
||||
[SettingName("followlinked")] Chaos,
|
||||
}
|
||||
|
||||
public enum LinkedDrops {
|
||||
Unset,
|
||||
[SettingName("unset")] Default,
|
||||
Linked,
|
||||
Independent,
|
||||
}
|
||||
@@ -348,7 +380,7 @@
|
||||
Underworld,
|
||||
}
|
||||
|
||||
public enum Pottery {
|
||||
public enum PotShuffle {
|
||||
[SettingName("none")] Vanilla,
|
||||
[AdditionalSetting("--colorizepots")] Keys,
|
||||
[AdditionalSetting("--colorizepots")] Cave,
|
||||
@@ -357,7 +389,7 @@
|
||||
[AdditionalSetting("--colorizepots")] Clustered,
|
||||
[AdditionalSetting("--colorizepots")] NonEmpty,
|
||||
[AdditionalSetting("--colorizepots")] Dungeon,
|
||||
Lottery,
|
||||
[SettingName("lottery")] All,
|
||||
}
|
||||
|
||||
public enum PrizeShuffle {
|
||||
@@ -404,7 +436,7 @@
|
||||
[SettingName("always_light_cone")] AlwaysLightCone,
|
||||
[SettingName("no_dark_rooms")] NoDarkRooms,
|
||||
[SettingName("require_lamp")] [AddStartingItems("Lamp")] StartingLamp,
|
||||
[SettingName("always_in_logic")] AlwaysInLogic,
|
||||
[SettingName("always_in_logic")] DarkInLogic,
|
||||
}
|
||||
|
||||
public enum BombSettings {
|
||||
@@ -439,7 +471,7 @@
|
||||
|
||||
public enum TrapDoorMode {
|
||||
Vanilla,
|
||||
Optional,
|
||||
[SettingName("optional")] Some,
|
||||
Boss,
|
||||
[SettingName("oneway")] RemoveAll,
|
||||
}
|
||||
@@ -460,6 +492,32 @@
|
||||
[AdditionalSetting("--ow_mixed")] TileSwap,
|
||||
}
|
||||
|
||||
public enum OverworldLayout {
|
||||
Vanilla,
|
||||
[SettingName("grid")] ShuffledGrid,
|
||||
[SettingName("wild")] Shuffled,
|
||||
}
|
||||
|
||||
public enum OverworldWorldLayouts {
|
||||
Parallel,
|
||||
[AdditionalSetting("--ow_unparallel")] Independent,
|
||||
}
|
||||
|
||||
public enum OverworldLayoutEdges {
|
||||
Unrestricted,
|
||||
[AdditionalSetting("--ow_keepsimilar")] Grouped,
|
||||
}
|
||||
|
||||
public enum OverworldLayoutTerrain {
|
||||
SameOnly,
|
||||
[AdditionalSetting("--ow_terrain")] AllowMixed,
|
||||
}
|
||||
|
||||
public enum OverworldMapFog {
|
||||
Fog,
|
||||
[AdditionalSetting("--ow_no_fog")] NoFog,
|
||||
}
|
||||
|
||||
public enum DamageChallengeMode {
|
||||
Normal,
|
||||
OHKO,
|
||||
|
||||
@@ -4,11 +4,15 @@
|
||||
|
||||
public class ServiceOptions {
|
||||
public string Baserom { get; set; } = null!;
|
||||
public string PythonPath { get; set; } = null!;
|
||||
public string FlipsPath { get; set; } = null!;
|
||||
public IList<string> AllowedCors { get; set; } = new List<string>();
|
||||
public AzureSettings AzureSettings { get; set; } = new AzureSettings();
|
||||
public IDictionary<string, string> RandomizerPaths { get; set; } = new Dictionary<string, string>();
|
||||
public List<string> AllowedCors { get; set; } = [];
|
||||
public AzureSettings AzureSettings { get; set; } = new();
|
||||
public Dictionary<string, GeneratorSettings> Generators { get; set; } = new();
|
||||
}
|
||||
|
||||
public class GeneratorSettings {
|
||||
public string WorkingDirectory { get; set; } = null!;
|
||||
public List<string> RandomizerCommand { get; set; } = [];
|
||||
}
|
||||
|
||||
public class AzureSettings {
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Serilog;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@@ -69,13 +68,10 @@
|
||||
builder.Services.AddSingleton(sp => sp);
|
||||
builder.Services.AddSingleton<AzureStorage>();
|
||||
builder.Services.AddSingleton<CommonSettingsProcessor>();
|
||||
builder.Services.AddSingleton<ProcessService>();
|
||||
builder.Services.AddSingleton<ShutdownHandler>();
|
||||
|
||||
builder.Services.AddKeyedScoped<IRandomizer, BaseRandomizer>(BaseRandomizer.Name);
|
||||
builder.Services.AddKeyedScoped<IRandomizer, BaseRandomizer>(BaseRandomizer.DungeonMapName);
|
||||
builder.Services.AddKeyedScoped<IRandomizer, Apr2025Randomizer>(Apr2025Randomizer.Name);
|
||||
builder.Services.AddScoped<BaseRandomizer>();
|
||||
|
||||
builder.Services.AddScoped<RandomizeService>();
|
||||
builder.Services.AddScoped<SeedService>();
|
||||
builder.Services.AddScoped<IdGenerator>();
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
namespace ALttPRandomizer.Randomizers {
|
||||
using ALttPRandomizer;
|
||||
using ALttPRandomizer.Azure;
|
||||
using ALttPRandomizer.Model;
|
||||
using ALttPRandomizer.Options;
|
||||
using ALttPRandomizer.Settings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class Apr2025Randomizer : IRandomizer {
|
||||
public const string Name = "apr2025";
|
||||
public const RandomizerInstance Instance = RandomizerInstance.Apr2025;
|
||||
|
||||
public Apr2025Randomizer(
|
||||
AzureStorage azureStorage,
|
||||
CommonSettingsProcessor settingsProcessor,
|
||||
IOptionsMonitor<ServiceOptions> optionsMonitor,
|
||||
ILogger<BaseRandomizer> logger) {
|
||||
AzureStorage = azureStorage;
|
||||
SettingsProcessor = settingsProcessor;
|
||||
OptionsMonitor = optionsMonitor;
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
private CommonSettingsProcessor SettingsProcessor { get; }
|
||||
private AzureStorage AzureStorage { get; }
|
||||
private IOptionsMonitor<ServiceOptions> OptionsMonitor { get; }
|
||||
private ILogger<BaseRandomizer> Logger { get; }
|
||||
private ServiceOptions Configuration => OptionsMonitor.CurrentValue;
|
||||
|
||||
public void Validate(SeedSettings settings) {
|
||||
this.SettingsProcessor.ValidateSettings(Instance, settings);
|
||||
}
|
||||
|
||||
public async Task Randomize(string id, SeedSettings settings, bool uploadSettings = true) {
|
||||
Logger.LogDebug("Recieved request for id {id} to randomize settings {@settings}", id, settings);
|
||||
|
||||
var start = new ProcessStartInfo() {
|
||||
FileName = Configuration.PythonPath,
|
||||
WorkingDirectory = Configuration.RandomizerPaths[Name],
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
|
||||
var args = start.ArgumentList;
|
||||
args.Add("EntranceRandomizer.py");
|
||||
args.Add("--rom");
|
||||
args.Add(Configuration.Baserom);
|
||||
|
||||
args.Add("--outputpath");
|
||||
args.Add(Path.GetTempPath());
|
||||
|
||||
args.Add("--outputname");
|
||||
args.Add(id);
|
||||
|
||||
args.Add("--json_spoiler");
|
||||
|
||||
args.Add("--quickswap");
|
||||
|
||||
foreach (var arg in SettingsProcessor.GetSettings(Instance, settings)) {
|
||||
args.Add(arg);
|
||||
}
|
||||
|
||||
Logger.LogInformation("Randomizing with args: {args}", string.Join(" ", args));
|
||||
|
||||
var generating = string.Format("{0}/generating", id);
|
||||
await AzureStorage.UploadFile(generating, BinaryData.Empty);
|
||||
|
||||
var process = Process.Start(start) ?? throw new GenerationFailedException("Process failed to start.");
|
||||
process.EnableRaisingEvents = true;
|
||||
|
||||
process.OutputDataReceived += (_, args) => Logger.LogInformation("Randomizer STDOUT: {output}", args.Data);
|
||||
process.ErrorDataReceived += (_, args) => Logger.LogInformation("Randomizer STDERR: {output}", args.Data);
|
||||
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
process.Exited += async (sender, args) => {
|
||||
var exitcode = process.ExitCode;
|
||||
|
||||
if (exitcode != 0) {
|
||||
await GenerationFailed(id, exitcode);
|
||||
} else {
|
||||
await GenerationSucceeded(id, settings);
|
||||
}
|
||||
};
|
||||
|
||||
if (uploadSettings) {
|
||||
var settingsJson = JsonSerializer.SerializeToDocument(settings, JsonOptions.Default);
|
||||
var settingsOut = string.Format("{0}/settings.json", id);
|
||||
await AzureStorage.UploadFile(settingsOut, new BinaryData(settingsJson));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task GenerationSucceeded(string id, SeedSettings settings) {
|
||||
var rom = Path.Join(Path.GetTempPath(), string.Format("ER_{0}.sfc", id));
|
||||
|
||||
var spoilerIn = Path.Join(Path.GetTempPath(), string.Format("ER_{0}_Spoiler.json", id));
|
||||
var spoilerOut = string.Format("{0}/spoiler.json", id);
|
||||
var uploadSpoiler = AzureStorage.UploadFileAndDelete(spoilerOut, spoilerIn);
|
||||
|
||||
var metaIn = Path.Join(Path.GetTempPath(), string.Format("ER_{0}_Meta.json", id));
|
||||
var metaOut = string.Format("{0}/meta.json", id);
|
||||
var uploadMeta = AzureStorage.UploadFileAndDelete(metaOut, metaIn);
|
||||
|
||||
var bpsIn = Path.Join(Path.GetTempPath(), string.Format("ER_{0}.bps", id));
|
||||
|
||||
var flips = new ProcessStartInfo() {
|
||||
FileName = Configuration.FlipsPath,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
var args = flips.ArgumentList;
|
||||
args.Add("--create");
|
||||
args.Add(Configuration.Baserom);
|
||||
args.Add(rom);
|
||||
args.Add(bpsIn);
|
||||
|
||||
var process = Process.Start(flips) ?? throw new GenerationFailedException("Process failed to start.");
|
||||
process.EnableRaisingEvents = true;
|
||||
|
||||
process.OutputDataReceived += (_, args) => Logger.LogInformation("flips STDOUT: {output}", args.Data);
|
||||
process.ErrorDataReceived += (_, args) => Logger.LogInformation("flips STDERR: {output}", args.Data);
|
||||
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
await process.WaitForExitAsync();
|
||||
|
||||
if (process.ExitCode != 0) {
|
||||
await this.GenerationFailed(id, process.ExitCode);
|
||||
return;
|
||||
}
|
||||
|
||||
var bpsOut = string.Format("{0}/patch.bps", id);
|
||||
var uploadPatch = AzureStorage.UploadFileAndDelete(bpsOut, bpsIn);
|
||||
|
||||
var generating = string.Format("{0}/generating", id);
|
||||
var deleteGenerating = AzureStorage.DeleteFile(generating);
|
||||
|
||||
await Task.WhenAll(uploadPatch, uploadSpoiler, uploadMeta, deleteGenerating);
|
||||
|
||||
Logger.LogDebug("Deleting file {filepath}", rom);
|
||||
File.Delete(rom);
|
||||
|
||||
Logger.LogInformation("Finished uploading seed id {id}", id);
|
||||
}
|
||||
|
||||
private async Task GenerationFailed(string id, int exitcode) {
|
||||
var generating = string.Format("{0}/generating", id);
|
||||
var deleteGenerating = AzureStorage.DeleteFile(generating);
|
||||
|
||||
await Task.WhenAll(deleteGenerating);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,33 +3,32 @@
|
||||
using ALttPRandomizer.Azure;
|
||||
using ALttPRandomizer.Model;
|
||||
using ALttPRandomizer.Options;
|
||||
using ALttPRandomizer.Service;
|
||||
using ALttPRandomizer.Settings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class BaseRandomizer : IRandomizer {
|
||||
public const string Name = "base";
|
||||
public const string DungeonMapName = "dungeon_map";
|
||||
|
||||
public const int MULTI_TRIES = 100;
|
||||
public const int SINGLE_TRIES = 5;
|
||||
|
||||
public BaseRandomizer(
|
||||
AzureStorage azureStorage,
|
||||
CommonSettingsProcessor settingsProcessor,
|
||||
ProcessService processService,
|
||||
IdGenerator idGenerator,
|
||||
ShutdownHandler shutdownHandler,
|
||||
IOptionsMonitor<ServiceOptions> optionsMonitor,
|
||||
ILogger<BaseRandomizer> logger) {
|
||||
this.AzureStorage = azureStorage;
|
||||
this.SettingsProcessor = settingsProcessor;
|
||||
this.ProcessService = processService;
|
||||
this.IdGenerator = idGenerator;
|
||||
this.ShutdownHandler = shutdownHandler;
|
||||
this.OptionsMonitor = optionsMonitor;
|
||||
@@ -38,6 +37,7 @@
|
||||
|
||||
private CommonSettingsProcessor SettingsProcessor { get; }
|
||||
private AzureStorage AzureStorage { get; }
|
||||
private ProcessService ProcessService { get; }
|
||||
private IdGenerator IdGenerator { get; }
|
||||
private IOptionsMonitor<ServiceOptions> OptionsMonitor { get; }
|
||||
private ILogger<BaseRandomizer> Logger { get; }
|
||||
@@ -57,12 +57,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
private IList<string> GetArgs(SeedSettings settings) {
|
||||
var args = new List<string>() {
|
||||
"--reduce_flashing",
|
||||
"--quickswap",
|
||||
"--shuffletavern",
|
||||
};
|
||||
private List<string> GetArgs(SeedSettings settings) {
|
||||
var args = new List<string>();
|
||||
|
||||
if (settings.Randomizer != RandomizerInstance.Apr2025) {
|
||||
args.Add("--shuffletavern");
|
||||
}
|
||||
|
||||
if (settings.DoorShuffle == DoorShuffle.Vanilla) {
|
||||
settings.DoorTypeMode = DoorTypeMode.Original;
|
||||
@@ -73,52 +73,32 @@
|
||||
}
|
||||
|
||||
if (settings.DoorShuffle != DoorShuffle.Vanilla || settings.DropShuffle != DropShuffle.Vanilla
|
||||
|| (settings.Pottery != Pottery.Vanilla && settings.Pottery != Pottery.Cave)) {
|
||||
|| (settings.PotShuffle != PotShuffle.Vanilla && settings.PotShuffle != PotShuffle.Cave)) {
|
||||
args.Add("--dungeon_counters=on");
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
private async Task StartProcess(string randomizerName, string id, IEnumerable<string> settings, Func<int, Task> completed) {
|
||||
var start = new ProcessStartInfo() {
|
||||
FileName = Configuration.PythonPath,
|
||||
WorkingDirectory = Configuration.RandomizerPaths[randomizerName],
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
private async Task StartProcess(GeneratorSettingsAttribute generatorSettings, string id, IEnumerable<string> settings, Func<int, Task> completed) {
|
||||
var generatorConfigSettings = this.Configuration.Generators[generatorSettings.Name];
|
||||
|
||||
var args = start.ArgumentList;
|
||||
args.Add("DungeonRandomizer.py");
|
||||
args.Add("--rom");
|
||||
args.Add(Configuration.Baserom);
|
||||
args.Add("--bps");
|
||||
|
||||
args.Add("--outputpath");
|
||||
args.Add(Path.GetTempPath());
|
||||
|
||||
args.Add("--outputname");
|
||||
args.Add(id);
|
||||
|
||||
args.Add("--spoiler=json");
|
||||
|
||||
foreach (var arg in settings) {
|
||||
args.Add(arg);
|
||||
}
|
||||
|
||||
Logger.LogInformation("Randomizing {id} with args: {args}", id, string.Join(" ", args.Select(arg => $"\"{arg}\"")));
|
||||
string[] args = [
|
||||
.. generatorConfigSettings.RandomizerCommand,
|
||||
.. generatorSettings.Args,
|
||||
"--rom",
|
||||
Configuration.Baserom,
|
||||
"--outputpath",
|
||||
Path.GetTempPath(),
|
||||
"--outputname",
|
||||
id,
|
||||
.. settings,
|
||||
];
|
||||
|
||||
var generating = string.Format("{0}/generating", id);
|
||||
await AzureStorage.UploadFile(generating, BinaryData.Empty);
|
||||
|
||||
var process = Process.Start(start) ?? throw new GenerationFailedException("Process failed to start.");
|
||||
process.EnableRaisingEvents = true;
|
||||
|
||||
process.OutputDataReceived += (_, args) => Logger.LogInformation("Randomizer {id} STDOUT: {output}", id, args.Data);
|
||||
process.ErrorDataReceived += (_, args) => Logger.LogInformation("Randomizer {id} STDERR: {output}", id, args.Data);
|
||||
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
var process = this.ProcessService.StartProcess($"Generation {id}", generatorConfigSettings.WorkingDirectory, args);
|
||||
|
||||
this.ShutdownHandler.AddId(id);
|
||||
|
||||
@@ -136,13 +116,20 @@
|
||||
public async Task Randomize(string id, SeedSettings settings, bool uploadSettings = true) {
|
||||
Logger.LogDebug("Recieved request for id {id} to randomize settings {@settings}", id, settings);
|
||||
|
||||
var args = this.GetArgs(settings).Append(string.Format("--tries={0}", SINGLE_TRIES));
|
||||
var args = this.GetArgs(settings);
|
||||
|
||||
await StartProcess(this.SettingsProcessor.GetRandomizerName(settings.Randomizer), id, args, async exitcode => {
|
||||
if (settings.Randomizer != RandomizerInstance.Apr2025) {
|
||||
args.Add($"--tries={SINGLE_TRIES}");
|
||||
args.Add($"--rom_header={id}");
|
||||
}
|
||||
|
||||
var generatorSettings = this.SettingsProcessor.GetGeneratorSettings(settings.Randomizer);
|
||||
|
||||
await StartProcess(generatorSettings, id, args, async exitcode => {
|
||||
if (exitcode != 0) {
|
||||
await GenerationFailed(id, exitcode);
|
||||
} else {
|
||||
await SingleSucceeded(id);
|
||||
await SingleSucceeded(generatorSettings, id);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -154,7 +141,8 @@
|
||||
}
|
||||
|
||||
public async Task RandomizeMultiworld(string id, IList<SeedSettings> settings, bool uploadSettings = true) {
|
||||
var randomizerName = this.SettingsProcessor.GetRandomizerName(settings[0].Randomizer);
|
||||
var generatorSettings = this.SettingsProcessor.GetGeneratorSettings(settings[0].Randomizer);
|
||||
|
||||
Logger.LogDebug("Recieved request for id {id} to randomize multiworld settings {@settings}", id, settings);
|
||||
|
||||
var names = settings.Select(s => s.PlayerName.Replace(' ', '_')).ToList();
|
||||
@@ -162,13 +150,14 @@
|
||||
var args = settings.Select((s, idx) => string.Format("--p{0}={1}", idx + 1, string.Join(" ", this.GetArgs(s))))
|
||||
.Append(string.Format("--names={0}", string.Join(",", names)))
|
||||
.Append(string.Format("--multi={0}", settings.Count))
|
||||
.Append(string.Format("--tries={0}", MULTI_TRIES));
|
||||
.Append(string.Format("--tries={0}", MULTI_TRIES))
|
||||
.Append(string.Format("--rom_header={0}", id));
|
||||
|
||||
await StartProcess(randomizerName, id, args, async exitcode => {
|
||||
await StartProcess(generatorSettings, id, args, async exitcode => {
|
||||
if (exitcode != 0) {
|
||||
await GenerationFailed(id, exitcode);
|
||||
} else {
|
||||
await MultiSucceeded(id, settings, names);
|
||||
await MultiSucceeded(generatorSettings, id, settings, names);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -179,98 +168,122 @@
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SingleSucceeded(string id) {
|
||||
try {
|
||||
var basename = string.Format("OR_{0}", id);
|
||||
await this.UploadFiles(id, basename, 1, null);
|
||||
private async Task<int> GeneratePatch(string id, string basename) {
|
||||
var tempPath = Path.GetTempPath();
|
||||
var bps = Path.Join(tempPath, string.Format("{0}.bps", basename));
|
||||
var sfc = Path.Join(tempPath, string.Format("{0}.sfc", basename));
|
||||
|
||||
var metaIn = Path.Join(Path.GetTempPath(), string.Format("OR_{0}_Meta.json", id));
|
||||
var process = this.ProcessService.StartProcess($"Generation {id}", tempPath, this.Configuration.FlipsPath, "--create", this.Configuration.Baserom, sfc, bps);
|
||||
|
||||
await process.WaitForExitAsync();
|
||||
|
||||
return process.ExitCode;
|
||||
}
|
||||
|
||||
private async Task SingleSucceeded(GeneratorSettingsAttribute generatorSettings, string id) {
|
||||
try {
|
||||
var basename = $"{generatorSettings.Prefix}{id}";
|
||||
if (generatorSettings.RequireFlips) {
|
||||
var exitCode = await GeneratePatch(id, basename);
|
||||
|
||||
if (exitCode != 0) {
|
||||
await this.GenerationFailed(id, exitCode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await this.UploadFiles(id, basename);
|
||||
|
||||
var metaIn = Path.Join(Path.GetTempPath(), string.Format("{0}_Meta.json", basename));
|
||||
Logger.LogDebug("Deleting file {filepath}", metaIn);
|
||||
File.Delete(metaIn);
|
||||
|
||||
var spoilerIn = Path.Join(Path.GetTempPath(), string.Format("OR_{0}_Spoiler.json", id));
|
||||
var spoilerIn = Path.Join(Path.GetTempPath(), string.Format("{0}_Spoiler.json", basename));
|
||||
Logger.LogDebug("Deleting file {filepath}", spoilerIn);
|
||||
File.Delete(spoilerIn);
|
||||
|
||||
Logger.LogInformation("Finished uploading seed id {id}", id);
|
||||
} finally {
|
||||
var generating = string.Format("{0}/generating", id);
|
||||
await AzureStorage.DeleteFile(generating);
|
||||
await AzureStorage.DeleteFile($"{id}/generating");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UploadFiles(string id, string basename, int playerNum, string? parentId) {
|
||||
private async Task UploadFiles(string id, string basename, int playerNum = 1, string playerSuffix = "") {
|
||||
var tasks = new List<Task>();
|
||||
|
||||
var rom = Path.Join(Path.GetTempPath(), string.Format("{0}.sfc", basename));
|
||||
var rom = Path.Join(Path.GetTempPath(), string.Format("{0}{1}.sfc", basename, playerSuffix));
|
||||
Logger.LogDebug("Deleting file {filepath}", rom);
|
||||
File.Delete(rom);
|
||||
|
||||
var bpsIn = Path.Join(Path.GetTempPath(), string.Format("{0}.bps", basename));
|
||||
var bpsOut = string.Format("{0}/patch.bps", id);
|
||||
tasks.Add(this.AzureStorage.UploadFileAndDelete(bpsOut, bpsIn));
|
||||
var bpsIn = Path.Join(Path.GetTempPath(), string.Format("{0}{1}.bps", basename, playerSuffix));
|
||||
tasks.Add(this.AzureStorage.UploadFileAndDelete($"{id}/patch.bps", bpsIn));
|
||||
|
||||
var spoilerIn = Path.Join(Path.GetTempPath(), string.Format("OR_{0}_Spoiler.json", parentId ?? id));
|
||||
var spoilerOut = string.Format("{0}/spoiler.json", id);
|
||||
tasks.Add(this.AzureStorage.UploadFileFromSource(spoilerOut, spoilerIn));
|
||||
var spoilerIn = Path.Join(Path.GetTempPath(), string.Format("{0}_Spoiler.json", basename));
|
||||
tasks.Add(this.AzureStorage.UploadFileFromSource($"{id}/spoiler.json", spoilerIn));
|
||||
|
||||
var metaIn = Path.Join(Path.GetTempPath(), string.Format("OR_{0}_Meta.json", parentId ?? id));
|
||||
var metaOut = string.Format("{0}/meta.json", id);
|
||||
var metaIn = Path.Join(Path.GetTempPath(), string.Format("{0}_Meta.json", basename));
|
||||
var meta = ProcessMetadata(metaIn, playerNum);
|
||||
tasks.Add(this.AzureStorage.UploadFile(metaOut, new BinaryData(meta)));
|
||||
|
||||
if (parentId != null) {
|
||||
var parentOut = string.Format("{0}/parent", id);
|
||||
tasks.Add(this.AzureStorage.UploadFile(parentOut, new BinaryData(parentId)));
|
||||
}
|
||||
tasks.Add(this.AzureStorage.UploadFile($"{id}/meta.json", new BinaryData(meta)));
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
private async Task MultiSucceeded(string id, IList<SeedSettings> settings, IList<string> names) {
|
||||
private async Task MultiSucceeded(GeneratorSettingsAttribute generatorSettings, string id, IList<SeedSettings> settings, List<string> names) {
|
||||
var tasks = new List<Task>();
|
||||
var subIds = new List<string>();
|
||||
var worlds = new List<object>();
|
||||
|
||||
try {
|
||||
var basename = $"{generatorSettings.Prefix}{id}";
|
||||
|
||||
for (var i = 0; i < settings.Count; i++) {
|
||||
var basename = string.Format("OR_{0}_P{1}_{2}", id, i + 1, names[i]);
|
||||
var playerSuffix = $"_P{i + 1}_{names[i]}";
|
||||
var randomId = this.IdGenerator.GenerateId();
|
||||
subIds.Add(randomId);
|
||||
tasks.Add(this.UploadFiles(randomId, basename, i + 1, id));
|
||||
|
||||
Task<int> flipsTask;
|
||||
if (generatorSettings.RequireFlips) {
|
||||
flipsTask = this.GeneratePatch(id, $"{basename}{playerSuffix}");
|
||||
} else {
|
||||
flipsTask = Task.FromResult(0);
|
||||
}
|
||||
|
||||
tasks.Add(flipsTask.ContinueWith(exitCode => {
|
||||
if (exitCode.Result != 0) {
|
||||
this.Logger.LogWarning("Generation {id} - flips failed with exit code {exitCode}", id, exitCode);
|
||||
}
|
||||
|
||||
return this.UploadFiles(randomId, basename, i + 1, playerSuffix);
|
||||
}));
|
||||
|
||||
tasks.Add(this.AzureStorage.UploadFile($"{randomId}/parent", new BinaryData(id)));
|
||||
|
||||
worlds.Add(new { Name = settings[i].PlayerName, Id = randomId });
|
||||
|
||||
var settingsJson = JsonSerializer.SerializeToDocument(settings[i], JsonOptions.Default);
|
||||
var settingsOut = string.Format("{0}/settings.json", randomId);
|
||||
tasks.Add(this.AzureStorage.UploadFile(settingsOut, new BinaryData(settingsJson)));
|
||||
tasks.Add(this.AzureStorage.UploadFile($"{randomId}/settings.json", new BinaryData(settingsJson)));
|
||||
}
|
||||
|
||||
var worldsJson = JsonSerializer.SerializeToDocument(worlds, JsonOptions.Default);
|
||||
var worldsOut = string.Format("{0}/worlds.json", id);
|
||||
|
||||
tasks.Add(this.AzureStorage.UploadFile(worldsOut, new BinaryData(worldsJson)));
|
||||
tasks.Add(this.AzureStorage.UploadFile($"{id}/worlds.json", new BinaryData(worldsJson)));
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
var metaIn = Path.Join(Path.GetTempPath(), string.Format("OR_{0}_Meta.json", id));
|
||||
var metaOut = string.Format("{0}/meta.json", id);
|
||||
var uploadMeta = AzureStorage.UploadFileAndDelete(metaOut, metaIn);
|
||||
var metaIn = Path.Join(Path.GetTempPath(), string.Format("{0}_Meta.json", basename));
|
||||
var uploadMeta = AzureStorage.UploadFileAndDelete($"{id}/meta.json", metaIn);
|
||||
|
||||
var spoilerIn = Path.Join(Path.GetTempPath(), string.Format("OR_{0}_Spoiler.json", id));
|
||||
var spoilerOut = string.Format("{0}/spoiler.json", id);
|
||||
var uploadSpoiler = AzureStorage.UploadFileAndDelete(spoilerOut, spoilerIn);
|
||||
var spoilerIn = Path.Join(Path.GetTempPath(), string.Format("{0}_Spoiler.json", basename));
|
||||
var uploadSpoiler = AzureStorage.UploadFileAndDelete($"{id}/spoiler.json", spoilerIn);
|
||||
|
||||
var multidataIn = Path.Join(Path.GetTempPath(), string.Format("OR_{0}_multidata", id));
|
||||
var multidataOut = string.Format("{0}/multidata", id);
|
||||
var uploadMultidata = AzureStorage.UploadFileAndDelete(multidataOut, multidataIn);
|
||||
var multidataIn = Path.Join(Path.GetTempPath(), string.Format("{0}_multidata", basename));
|
||||
var uploadMultidata = AzureStorage.UploadFileAndDelete($"{id}/multidata", multidataIn);
|
||||
|
||||
await Task.WhenAll(uploadMeta, uploadSpoiler, uploadMultidata);
|
||||
|
||||
Logger.LogInformation("Finished uploading multiworld id {id}", id);
|
||||
} finally {
|
||||
var generating = string.Format("{0}/generating", id);
|
||||
var deleteGenerating = AzureStorage.DeleteFile(generating);
|
||||
await AzureStorage.DeleteFile(generating);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,11 +306,9 @@
|
||||
return JsonSerializer.SerializeToDocument(processed, JsonOptions.Default);
|
||||
}
|
||||
|
||||
private async Task GenerationFailed(string id, int exitcode) {
|
||||
private async Task GenerationFailed(string id, int _) {
|
||||
var generating = string.Format("{0}/generating", id);
|
||||
var deleteGenerating = AzureStorage.DeleteFile(generating);
|
||||
|
||||
await Task.WhenAll(deleteGenerating);
|
||||
await AzureStorage.DeleteFile(generating);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
ALttPRandomizer/Service/ProcessService.cs
Normal file
41
ALttPRandomizer/Service/ProcessService.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
namespace ALttPRandomizer.Service {
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public class ProcessService {
|
||||
public ProcessService(ILogger<ProcessService> logger) {
|
||||
this.Logger = logger;
|
||||
}
|
||||
|
||||
public ILogger<ProcessService> Logger { get; }
|
||||
|
||||
public Process StartProcess(string logPrefix, string workingDirectory, params string[] args) {
|
||||
var start = new ProcessStartInfo(args[0], args.Skip(1)) {
|
||||
WorkingDirectory = workingDirectory,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
|
||||
this.Logger.LogInformation("{prefix} - executing command: {command}", logPrefix, string.Join(" ", args.Select(arg => arg.Contains(' ') ? $"\"{arg}\"" : arg)));
|
||||
|
||||
var process = Process.Start(start) ?? throw new GenerationFailedException("{0} - Process failed to start.", logPrefix);
|
||||
process.EnableRaisingEvents = true;
|
||||
|
||||
process.OutputDataReceived += (_, args) => {
|
||||
if (args.Data != null) {
|
||||
Logger.LogInformation("{prefix} - STDOUT: {output}", logPrefix, args.Data);
|
||||
}
|
||||
};
|
||||
process.ErrorDataReceived += (_, args) => {
|
||||
if (args.Data != null) {
|
||||
Logger.LogInformation("{prefix} - STDERR: {output}", logPrefix, args.Data);
|
||||
}
|
||||
};
|
||||
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
return process;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,18 @@
|
||||
using ALttPRandomizer.Azure;
|
||||
using ALttPRandomizer.Model;
|
||||
using ALttPRandomizer.Randomizers;
|
||||
using ALttPRandomizer.Settings;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class RandomizeService {
|
||||
public RandomizeService(
|
||||
IdGenerator idGenerator,
|
||||
IServiceProvider serviceProvider,
|
||||
BaseRandomizer baseRandomizer,
|
||||
AzureStorage azureStorage,
|
||||
ILogger<RandomizeService> logger) {
|
||||
this.IdGenerator = idGenerator;
|
||||
this.ServiceProvider = serviceProvider;
|
||||
this.BaseRandomizer = baseRandomizer;
|
||||
this.AzureStorage = azureStorage;
|
||||
this.Logger = logger;
|
||||
@@ -29,25 +23,15 @@
|
||||
|
||||
private IdGenerator IdGenerator { get; }
|
||||
private BaseRandomizer BaseRandomizer { get; }
|
||||
private IServiceProvider ServiceProvider { get; }
|
||||
private AzureStorage AzureStorage { get; }
|
||||
|
||||
public async Task<string> RandomizeSeed(SeedSettings settings, string? seedId = null) {
|
||||
var id = seedId ?? this.IdGenerator.GenerateId();
|
||||
this.Logger.LogInformation("Generating seed {seedId} with settings {@settings}", id, settings);
|
||||
|
||||
var fi = typeof(RandomizerInstance).GetField(settings.Randomizer.ToString(), BindingFlags.Static | BindingFlags.Public);
|
||||
this.BaseRandomizer.Validate(settings);
|
||||
|
||||
var randomizerKey = fi?.GetCustomAttribute<RandomizerNameAttribute>()?.Name;
|
||||
|
||||
if (randomizerKey == null) {
|
||||
throw new InvalidSettingsException("Invalid randomizer: {0}", settings.Randomizer);
|
||||
}
|
||||
|
||||
var randomizer = this.ServiceProvider.GetRequiredKeyedService<IRandomizer>(randomizerKey);
|
||||
randomizer.Validate(settings);
|
||||
|
||||
await randomizer.Randomize(id, settings, seedId == null);
|
||||
await this.BaseRandomizer.Randomize(id, settings, seedId == null);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,25 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
internal class RandomizerNameAttribute : Attribute {
|
||||
public RandomizerNameAttribute(string name) {
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
internal class GeneratorSettingsAttribute : Attribute {
|
||||
public GeneratorSettingsAttribute(string name, string prefix, params string[] args) {
|
||||
this.Name = name;
|
||||
this.Prefix = prefix;
|
||||
this.Args = args;
|
||||
}
|
||||
|
||||
public GeneratorSettingsAttribute(string name, string prefix, bool requireFlips, params string[] args) {
|
||||
this.Name = name;
|
||||
this.Prefix = prefix;
|
||||
this.Args = args;
|
||||
this.RequireFlips = requireFlips;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public string Prefix { get; }
|
||||
public string[] Args { get; }
|
||||
public bool RequireFlips { get; } = false;
|
||||
}
|
||||
|
||||
internal abstract class RandomizerSpecificAttribute : Attribute {
|
||||
@@ -42,21 +55,27 @@
|
||||
internal class NoSettingNameAttribute : RandomizerSpecificAttribute {
|
||||
public NoSettingNameAttribute() : base(null) { }
|
||||
|
||||
public NoSettingNameAttribute(RandomizerInstance[] randomizers) : base(randomizers) { }
|
||||
public NoSettingNameAttribute(params RandomizerInstance[] randomizers) : base(randomizers) { }
|
||||
}
|
||||
|
||||
internal class IgnoreSettingAttribute : RandomizerSpecificAttribute {
|
||||
public IgnoreSettingAttribute(params RandomizerInstance[] randomizers) : base(randomizers) { }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple=true)]
|
||||
internal class AdditionalSettingAttribute : RandomizerSpecificAttribute {
|
||||
public AdditionalSettingAttribute(string setting) : base(null) {
|
||||
this.Setting = setting;
|
||||
public AdditionalSettingAttribute(params string[] settings) : base(null) {
|
||||
this.Settings = settings;
|
||||
}
|
||||
|
||||
public AdditionalSettingAttribute(RandomizerInstance[] randomizers, string setting) : base(randomizers) {
|
||||
this.Setting = setting;
|
||||
public AdditionalSettingAttribute(RandomizerInstance[] randomizers, params string[] settings) : base(randomizers) {
|
||||
this.Settings = settings;
|
||||
}
|
||||
|
||||
public string Setting { get; }
|
||||
public string[] Settings { get; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple=true)]
|
||||
internal class AddStartingItemsAttribute : RandomizerSpecificAttribute {
|
||||
public AddStartingItemsAttribute(params string[] items) : base(null) {
|
||||
this.Items = items;
|
||||
@@ -69,6 +88,7 @@
|
||||
public string[] Items { get; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple=true)]
|
||||
internal class RequiredSettingAttribute : RandomizerSpecificAttribute {
|
||||
public RequiredSettingAttribute(params object[] values) : base(null) {
|
||||
this.Values = values;
|
||||
@@ -81,6 +101,7 @@
|
||||
public object[] Values { get; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple=true)]
|
||||
internal class ForbiddenSettingAttribute : RandomizerSpecificAttribute {
|
||||
public ForbiddenSettingAttribute(params object[] values) : base(null) {
|
||||
this.Values = values;
|
||||
|
||||
@@ -13,11 +13,16 @@
|
||||
if (prop.Name == nameof(SeedSettings.PlayerName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var value = prop.GetValue(settings) ?? throw new SettingsLookupException("settings.{0} not found", prop.Name);
|
||||
var valueFieldName = value.ToString() ?? throw new SettingsLookupException("settings.{0}.ToString() returned null", prop.Name);
|
||||
var fi = prop.PropertyType.GetField(valueFieldName, BindingFlags.Static | BindingFlags.Public)
|
||||
?? throw new SettingsLookupException("Could not get field info for value {0}.{1}", prop.PropertyType, valueFieldName);
|
||||
|
||||
if (prop.GetCustomAttributes<IgnoreSettingAttribute>().Any(att => att.HasRandomizer(randomizer))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!prop.GetCustomAttributes<NoSettingNameAttribute>().Any(att => att.HasRandomizer(randomizer))) {
|
||||
var settingName =
|
||||
prop.GetCustomAttributes<SettingNameAttribute>()
|
||||
@@ -30,7 +35,9 @@
|
||||
}
|
||||
|
||||
foreach (var att in fi.GetCustomAttributes<AdditionalSettingAttribute>().Where(att => att.HasRandomizer(randomizer))) {
|
||||
yield return att.Setting;
|
||||
foreach (var setting in att.Settings) {
|
||||
yield return setting;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var att in fi.GetCustomAttributes<AddStartingItemsAttribute>().Where(att => att.HasRandomizer(randomizer))) {
|
||||
@@ -65,25 +72,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
public string GetRandomizerName(RandomizerInstance randomizer)
|
||||
internal GeneratorSettingsAttribute GetGeneratorSettings(RandomizerInstance randomizer)
|
||||
{
|
||||
var fi = typeof(RandomizerInstance).GetField(randomizer.ToString(), BindingFlags.Static | BindingFlags.Public);
|
||||
|
||||
var randomizerKey = fi?.GetCustomAttribute<RandomizerNameAttribute>()?.Name;
|
||||
var settings = fi?.GetCustomAttribute<GeneratorSettingsAttribute>();
|
||||
|
||||
if (randomizerKey == null) {
|
||||
throw new InvalidSettingsException("Invalid randomizer: {0}", randomizerKey);
|
||||
if (settings == null) {
|
||||
throw new InvalidSettingsException("Invalid randomizer: {0}", randomizer);
|
||||
}
|
||||
|
||||
return randomizerKey;
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
public class SettingsLookupException : Exception {
|
||||
public SettingsLookupException(string message, params object?[] args) : base(string.Format(message, args)) { }
|
||||
}
|
||||
public class SettingsLookupException(string message, params object?[] args) : Exception(string.Format(message, args)) { }
|
||||
|
||||
public class InvalidSettingsException : Exception {
|
||||
public InvalidSettingsException(string message, params object?[] args) : base(string.Format(message, args)) { }
|
||||
}
|
||||
public class InvalidSettingsException(string message, params object?[] args) : Exception(string.Format(message, args)) { }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"ALttPRandomizer": {
|
||||
"baserom": "/randomizer/alttp.sfc",
|
||||
"pythonPath": "/usr/bin/python3",
|
||||
"baserom": "/baserom/alttp.sfc",
|
||||
"flipsPath": "/flips/flips",
|
||||
"allowedCors": [
|
||||
"https://new.alttpr.gwaa.kiwi",
|
||||
@@ -12,10 +11,19 @@
|
||||
"clientId": "a48d5ae1-fa0a-4e33-9586-18c0eca0a28c",
|
||||
"blobstoreEndpoint": "https://alttprstorage.blob.core.windows.net/seeds"
|
||||
},
|
||||
"randomizerPaths": {
|
||||
"base": "/randomizer",
|
||||
"apr2025": "/apr2025_randomizer",
|
||||
"dungeon_map": "/dungeon_map_randomizer"
|
||||
"generators": {
|
||||
"base": {
|
||||
"workingDirectory": "/randomizer",
|
||||
"randomizerCommand": [ "uv", "run", "DungeonRandomizer.py" ],
|
||||
},
|
||||
"apr2025": {
|
||||
"workingDirectory": "/apr2025_randomizer",
|
||||
"randomizerCommand": [ "uv", "run", "EntranceRandomizer.py" ],
|
||||
},
|
||||
"beta": {
|
||||
"workingDirectory": "/beta_randomizer",
|
||||
"randomizerCommand": [ "uv", "run", "DungeonRandomizer.py" ],
|
||||
},
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
|
||||
Submodule Apr2025Randomizer updated: 84adf1dd89...029e8de852
Submodule BaseRandomizer updated: ea8498f402...61d7940183
1
BetaRandomizer
Submodule
1
BetaRandomizer
Submodule
Submodule BetaRandomizer added at b1a71ef9b1
34
Dockerfile
34
Dockerfile
@@ -20,37 +20,39 @@ EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
RUN tdnf install -y python3
|
||||
RUN python3 -m ensurepip --default-pip --upgrade
|
||||
RUN pip install uv
|
||||
|
||||
RUN mkdir -p /flips
|
||||
COPY --from=build /flips/Flips-198/flips /flips/flips
|
||||
|
||||
RUN mkdir -p /randomizer/data
|
||||
RUN touch /randomizer/data/base2current.json
|
||||
RUN chown $APP_UID:$APP_UID /randomizer/data/base2current.json
|
||||
|
||||
RUN mkdir -p /dungeon_map_randomizer/data
|
||||
RUN touch /dungeon_map_randomizer/data/base2current.json
|
||||
RUN chown $APP_UID:$APP_UID /dungeon_map_randomizer/data/base2current.json
|
||||
|
||||
USER $APP_UID
|
||||
|
||||
RUN python3 -m ensurepip --upgrade
|
||||
COPY alttp.sfc /baserom/alttp.sfc
|
||||
|
||||
# base generator
|
||||
WORKDIR /randomizer
|
||||
COPY alttp.sfc .
|
||||
|
||||
COPY BaseRandomizer/resources/app/meta/manifests/pip_requirements.txt requirements.txt
|
||||
RUN python3 -m pip install -r requirements.txt
|
||||
COPY BaseRandomizer/pyproject.toml .
|
||||
RUN uv sync
|
||||
|
||||
COPY BaseRandomizer/ .
|
||||
|
||||
# apr2025 generator
|
||||
WORKDIR /apr2025_randomizer
|
||||
|
||||
COPY Apr2025Randomizer/pyproject.toml .
|
||||
RUN uv sync
|
||||
|
||||
COPY Apr2025Randomizer/ .
|
||||
|
||||
WORKDIR /dungeon_map_randomizer
|
||||
# beta generator
|
||||
WORKDIR /beta_randomizer
|
||||
|
||||
COPY DungeonMapRandomizer/ .
|
||||
COPY BetaRandomizer/pyproject.toml .
|
||||
RUN uv sync
|
||||
|
||||
COPY BetaRandomizer/ .
|
||||
|
||||
# web server
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/publish .
|
||||
COPY ALttPRandomizer/appsettings.Docker.json appsettings.json
|
||||
|
||||
Submodule DungeonMapRandomizer deleted from 67307a872c
1
PikitRandomizer
Submodule
1
PikitRandomizer
Submodule
Submodule PikitRandomizer added at 2738f61c0d
Reference in New Issue
Block a user