Skip to content

Commit

Permalink
- Added a constructor for loading other tilesets & audioset than default
Browse files Browse the repository at this point in the history
- Working audio in the browser ! (I hope it works on github pages)
  • Loading branch information
Mrcubix committed Sep 24, 2023
1 parent dcd430e commit 9cf2f01
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions ColorTiles/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class MainViewModel : ViewModelBase

public GameTileSet Tileset { get; set; }
public AudioSet? Audioset { get; set; } = null!;
public bool Disposed { get; private set; }

public HUDViewModel HUDViewModel
{
Expand Down Expand Up @@ -53,6 +54,25 @@ public MainViewModel()
AudiosetManager = new AudioSetManager();

Tileset = null!;
Audioset = null!;

MainMenuViewModel = new MainMenuViewModel();
GameOverMenuViewModel = new GameOverMenuViewModel();

HUDViewModel = null!;
GameBoardViewModel = null!;

Initialize();
PostInitialize();
}

public MainViewModel(GameTileSet tileset, AudioSet audioset)
{
TilesetManager = new TileSetManager();
AudiosetManager = new AudioSetManager();

Tileset = tileset;
Audioset = audioset;

MainMenuViewModel = new MainMenuViewModel();
GameOverMenuViewModel = new GameOverMenuViewModel();
Expand All @@ -66,15 +86,13 @@ public MainViewModel()

protected virtual void Initialize()
{
Tileset = TilesetManager.LoadDefault();
Tileset ??= TilesetManager.LoadDefault();

// Only supported on Desktop platforms at the moment (Issue need to be fixed in OpenTK to Detect Android & IOS properly)
if (OperatingSystem.IsWindows() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
{
// Initialize the audio device
AudiosetManager.InitializeAudio();
Audioset = AudiosetManager.LoadDefault();
}
if (!OperatingSystem.IsBrowser())
AudiosetManager.InitializeOpenAL();

Audioset ??= AudiosetManager.LoadDefault();

InitializeViewModels();
}
Expand Down Expand Up @@ -175,6 +193,9 @@ public void OnTimeExpired(object? sender, EventArgs e)

public void Dispose()
{
if (Disposed)
return;

UnsuscribeFromEvents();

// Dispose Image Side
Expand All @@ -183,6 +204,8 @@ public void Dispose()
AudiosetManager.Dispose();

GameBoardViewModel.Dispose();

Disposed = true;
}

public void UnsuscribeFromEvents()
Expand Down

0 comments on commit 9cf2f01

Please sign in to comment.