Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
.DS_Store
*.log
*.user
*.mlb
10 changes: 8 additions & 2 deletions CommandLine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public async Task Randomize()
var randomizer = new Hyrule(createAsm,palaceRooms);
var rom = await randomizer.Randomize(vanillaRomData!, configuration, UpdateProgress, cts.Token);

if (rom != null)
if (rom.romdata != null)
{

char os_sep = Path.DirectorySeparatorChar;
Expand All @@ -151,8 +151,14 @@ public async Task Randomize()
: Directory.GetCurrentDirectory();
}
string newFileName = $"{outpath}/Z2_{Seed}_{Flags}.nes";
File.WriteAllBytes(newFileName, rom);
await File.WriteAllBytesAsync(newFileName, rom.romdata);
logger.Info($"File {newFileName} has been created!");
if (rom.debuginfo != null)
{
var mlbfile = $"{outpath}/Z2_{Seed}_{Flags}.mlb";
await File.WriteAllTextAsync(mlbfile, rom.debuginfo);
logger.Info($"File {mlbfile} has been created!");
}
}
else
{
Expand Down
97 changes: 0 additions & 97 deletions CrossPlatformUI.Browser/BrowserJsEngine.cs

This file was deleted.

2 changes: 1 addition & 1 deletion CrossPlatformUI.Browser/CrossPlatformUI.Browser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<ItemGroup>
<PackageReference Include="Avalonia.Browser" Version="$(AvaloniaVersion)" />
<PackageReference Include="js65.interop" Version="1.0.0-alpha3" />
<PackageReference Include="js65.browser" Version="$(Js65Version)" />
</ItemGroup>

<ItemGroup>
Expand Down
52 changes: 51 additions & 1 deletion CrossPlatformUI.Browser/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices.JavaScript;
using System.Runtime.Versioning;
using System.Threading.Tasks;
Expand All @@ -8,6 +10,7 @@
using Avalonia.Browser;
using ReactiveUI.Avalonia;
using CrossPlatformUI.Services;
using js65;
using Z2Randomizer.RandomizerCore;

[assembly: SupportedOSPlatform("browser")]
Expand All @@ -20,6 +23,17 @@ internal sealed partial class Program
[JSImport("globalThis.window.SetTitle")]
internal static partial void SetTitle(string title);

private static string LoadTextFileCallback(string basePath, string relPath)
{
return _assembly.ReadResource(relPath);
}
private static byte[] LoadBinaryFileCallback(string basePath, string relPath)
{
return _assembly.ReadBinaryResource(relPath);
}

private static readonly Assembly _assembly = typeof(RandomizerConfiguration).Assembly;

private static Task Main(string[] args)
{
#if DEBUG
Expand All @@ -33,7 +47,7 @@ private static Task Main(string[] args)
{
App.ServiceContainer ??= new();

App.ServiceContainer.AddSingleton<Hyrule.NewAssemblerFn>((opts, debug) => new BrowserJsEngine(opts));
App.ServiceContainer.AddSingleton<Hyrule.NewAssemblerFn>(MakeBrowserAssembler);
App.FileSystemService = new BrowserFileService();
App.ServiceContainer.AddSingleton<IFileSystemService>(x => App.FileSystemService);

Expand All @@ -42,6 +56,17 @@ private static Task Main(string[] args)
.StartBrowserAppAsync("out");
}


public static Assembler MakeBrowserAssembler(Js65Options? options = null, bool debugJavaScript = false)
{
var callbacks = new Js65Callbacks
{
OnFileReadBinary = LoadBinaryFileCallback,
OnFileReadText = LoadTextFileCallback
};
return new BrowserJsEngine(options, callbacks);
}

public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
#if DEBUG
Expand All @@ -52,3 +77,28 @@ public static AppBuilder BuildAvaloniaApp()
MaxGpuResourceSizeBytes = 64 * 1024 * 1024, // Default is 28 MB
});
}

internal static class AssemblyExtensions
{
public static string ReadResource(this Assembly assembly, string name)
{
// Format: "{Namespace}.{Folder}.{filename}.{Extension}"
using var stream = assembly.GetManifestResourceStream(name)!;
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
public static async Task<string> ReadResourceAsync(this Assembly assembly, string name)
{
// Format: "{Namespace}.{Folder}.{filename}.{Extension}"
await using var stream = assembly.GetManifestResourceStream(name)!;
using StreamReader reader = new(stream);
return await reader.ReadToEndAsync();
}
public static byte[] ReadBinaryResource(this Assembly assembly, string name)
{
// Format: "{Namespace}.{Folder}.{filename}.{Extension}"
using var stream = assembly.GetManifestResourceStream(name)!;
using var reader = new BinaryReader(stream);
return reader.ReadBytes((int)stream.Length);
}
}
461 changes: 0 additions & 461 deletions CrossPlatformUI.Browser/wwwroot/libassembler.js

This file was deleted.

10 changes: 6 additions & 4 deletions CrossPlatformUI/ViewModels/GenerateRomViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@
{
var romdata = host.RomFileViewModel.RomData!.ToArray();
var output = await Task.Run(async () => await randomizer.Randomize(romdata, config, UpdateProgress, tokenSource.Token));
if(!tokenSource.IsCancellationRequested)
if(!tokenSource.IsCancellationRequested && output.success)
{
var flags = config.SerializeFlags();
var filename = $"Z2_{config.Seed}_{flags}.nes";
await files.SaveGeneratedBinaryFile(filename, output!, Main.OutputFilePath);

Check failure on line 100 in CrossPlatformUI/ViewModels/GenerateRomViewModel.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, x64, 10.0.x)

Argument 2: cannot convert from 'Z2Randomizer.RandomizerCore.RandomizerResult' to 'byte[]'
if (config.GenerateSpoiler)
{
var spoilerFilename = $"Z2_{config.Seed}_{flags}_spoiler.txt";
Expand All @@ -107,6 +107,9 @@
}
ProgressHeading = "Generation Complete";
ProgressBody = $"Hash: {randomizer.Hash}\n\nFile: {filename}";
} else if (!output.success)
{
throw new Exception(output.messages);
}
IsComplete = true;
}
Expand All @@ -116,16 +119,15 @@
lastError = e;
HasError = true;
string errorHeading, errorBody;
var userError = e as UserFacingException;
if (userError != null)
if (e is UserFacingException userError)
{
errorHeading = userError.Heading;
errorBody = userError.Message;
}
else
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached) { throw; }
// if (System.Diagnostics.Debugger.IsAttached) { throw; }
#endif
errorHeading = "Error Generating Seed";
errorBody = "Please report this on the discord";
Expand Down
8 changes: 5 additions & 3 deletions Desktop.Common/Desktop.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
<ItemGroup>
<ProjectReference Include="..\CrossPlatformUI\CrossPlatformUI.csproj" />
<ProjectReference Include="..\RandomizerCore\RandomizerCore.csproj" />
<PackageReference Include="Microsoft.ClearScript.V8.Native.linux-x64" Version="7.4.5" Condition="$([MSBuild]::IsOsPlatform('Linux')) and '$(TargetFramework)' != 'net10.0-browser'" />
<PackageReference Include="Microsoft.ClearScript.V8.Native.osx-arm64" Version="7.4.5" Condition="$([MSBuild]::IsOsPlatform('OSX')) and '$(TargetFramework)' != 'net10.0-browser'" />
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x64" Version="7.4.5" Condition="$([MSBuild]::IsOsPlatform('Windows')) and '$(TargetFramework)' != 'net10.0-browser'" />
<PackageReference Include="js65.clearscript" Version="$(Js65Version)" />

<PackageReference Include="Microsoft.ClearScript.V8.Native.linux-x64" Version="7.5.0" Condition="$([MSBuild]::IsOsPlatform('Linux')) and '$(TargetFramework)' != 'net10.0-browser'" />
<PackageReference Include="Microsoft.ClearScript.V8.Native.osx-arm64" Version="7.5.0" Condition="$([MSBuild]::IsOsPlatform('OSX')) and '$(TargetFramework)' != 'net10.0-browser'" />
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x64" Version="7.5.0" Condition="$([MSBuild]::IsOsPlatform('Windows')) and '$(TargetFramework)' != 'net10.0-browser'" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<Js65Version>1.0.7</Js65Version>
<AvaloniaVersion>11.3.11</AvaloniaVersion>
<DialogHostAvaloniaVersion>0.10.4</DialogHostAvaloniaVersion>
<MaterialAvaloniaVersion>3.13.4</MaterialAvaloniaVersion>
Expand Down
Loading
Loading