Files
Triforce-Source/launcher/App/Backend.Media.cs
ruckus7382sfgsgdf fb26495475 Triforce v0.5.2
The new launcher (Windows and Linux: the game's own look, music and settings, saves and mods pages, smaller updates in parts), benchmark mode (Find my best settings: the game tours four places by itself and writes its results), Quit and Restart in the pause menu under Mods, Squadala! in the Mods menu, battle music above 60 fps, menu text, the controller in the menus with the game in the background, the whole GameBanana list, RX 580 and RX 5000/6000 shader fixes, the pipeline cache kept through an update, async present black flashes, and faster builds.
2026-11-19 10:52:50 -06:00

63 lines
2.3 KiB
C#

using System.Text.Json.Nodes;
using Triforce.Core.GameFiles;
namespace Triforce.Launcher;
/// <summary>The player's own game as the page's art and sound: the title logo, Saria's Song and the menu sounds, read from
/// the .nup they dropped (or, once built, from the game folder's romfs) and kept decoded in the launcher's cache.</summary>
public sealed partial class Backend
{
GameMedia? media;
string? mediaFrom;
int mediaVersion;
byte[]? MediaFor(string kind, string name)
{
var m = media;
if (m == null) return null;
return kind == "png" ? m.Png(name) : kind == "wav" ? m.Wav(name) : null;
}
/// <summary>Use this game for the art and sounds (null: none). Decodes the logo set and the first music right away, so
/// the reveal shows them at once.</summary>
bool UseMedia(string? path)
{
if (path == mediaFrom && media != null) return true;
if (path == null)
{
var gone = media; media = null; mediaFrom = null; gone?.Source.Dispose();
SendMedia();
return false;
}
try
{
var src = GameSource.Open(path);
var m = new GameMedia(src, Path.Combine(dataDir, "media"));
var t = System.Diagnostics.Stopwatch.StartNew();
foreach (var n in GameMedia.LogoSet) m.PngFile(n);
m.WavFile("saria");
Log.Write($"media from {path}: logo + Saria's Song ready in {t.ElapsedMilliseconds} ms");
var old = media;
media = m; mediaFrom = path; mediaVersion++;
old?.Source.Dispose();
// the rest in the background
_ = Task.Run(() => { try { foreach (var id in GameMedia.Sounds.Keys) m.WavFile(id); } catch (Exception e) { Log.Write("media: " + e.Message); } });
SendMedia();
return true;
}
catch (Exception e)
{
// (a source without the game's files: keep what is shown now)
Log.Write("media from " + path + ": " + e.Message);
if (media == null) SendMedia();
return false;
}
}
void SendMedia()
{
var on = media != null;
Send(new JsonObject { ["t"] = "state", ["media"] = new JsonObject { ["art"] = on, ["music"] = on, ["sfx"] = on, ["v"] = mediaVersion } });
}
}