Dramatically decrease size

This commit is contained in:
CreepyCrafter24 2020-03-29 18:48:45 +02:00
parent 633c37eb89
commit 0932b0d0d0
13 changed files with 126 additions and 92 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
#Soundtrack data #Soundtrack data
testexetrisathlon/*.wav testexetrisathlon/*.mp3
# Created by https://www.gitignore.io/api/rider,csharp,visualstudio # Created by https://www.gitignore.io/api/rider,csharp,visualstudio

View File

@ -1,24 +1,32 @@
import os import os
import os.path import os.path
import wave
import youtube_dl import youtube_dl
import wave
os.chdir("testexetrisathlon") os.chdir("testexetrisathlon")
def dl_vid(url, outfile): def dl_vid(url, outfile, filetype):
ydl_opts = { ydl_opts = {
'outtmpl': outfile, 'outtmpl': outfile,
'noplaylist': True, 'noplaylist': True,
'continue_dl': True, 'continue_dl': True,
'postprocessors': [{ 'postprocessors': [{
'key': 'FFmpegExtractAudio', 'key': 'FFmpegExtractAudio',
'preferredcodec': 'wav' }] 'preferredcodec': filetype }]
} }
with youtube_dl.YoutubeDL(ydl_opts) as ydl: with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url]) ydl.download([url])
def merge_vids(infiles, outfile): def merge_vids(infiles, outfile):
#lStream = open("list.txt", "w")
#for infile in infiles:
# lStream.write("file '" + infile + ".wav'\n")
#lStream.close()
#os.system("ffmpeg -f concat -i list.txt -c copy " + outfile + ".mp3")
#os.remove("list.txt")
#for infile in infiles:
# os.remove(infile + ".mp3")
data= [] data= []
for infile in infiles: for infile in infiles:
w = wave.open(infile + ".wav", 'rb') w = wave.open(infile + ".wav", 'rb')
@ -31,21 +39,24 @@ def merge_vids(infiles, outfile):
output.writeframes(data[0][1]) output.writeframes(data[0][1])
output.writeframes(data[1][1]) output.writeframes(data[1][1])
output.close() output.close()
os.system("ffmpeg -y -i " + outfile + ".wav " + outfile + ".mp3")
os.remove(outfile + ".wav")
if not os.path.isfile("Intro.wav"): if not os.path.isfile("Intro.mp3"):
dl_vid("https://youtu.be/U06jlgpMtQs", "Intro") dl_vid("https://youtu.be/U06jlgpMtQs", "Intro", "mp3")
if not os.path.isfile("InGame1.wav"): if not os.path.isfile("InGame1.mp3"):
dl_vid("https://youtu.be/hueJrl83sOQ", "st1") dl_vid("https://youtu.be/hueJrl83sOQ", "st1", "wav")
dl_vid("https://youtu.be/7gSS4h47rLU", "st2") dl_vid("https://youtu.be/7gSS4h47rLU", "st2", "wav")
dl_vid("https://youtu.be/NDjDgvXlfVw", "st3") dl_vid("https://youtu.be/NDjDgvXlfVw", "st3", "wav")
merge_vids(["st1", "st2", "st3"], "InGame1") merge_vids(["st1", "st2", "st3"], "InGame1")
if not os.path.isfile("InGame2.wav"): if not os.path.isfile("InGame2.mp3"):
dl_vid("https://youtu.be/umEDct4BoGc", "st1") dl_vid("https://youtu.be/umEDct4BoGc", "st1", "wav")
dl_vid("https://youtu.be/NVpjt9gHlDw", "st2") dl_vid("https://youtu.be/NVpjt9gHlDw", "st2", "wav")
dl_vid("https://youtu.be/zgKazTrhXmI", "st3") dl_vid("https://youtu.be/zgKazTrhXmI", "st3", "wav")
merge_vids(["st1", "st2", "st3"], "InGame2") merge_vids(["st1", "st2", "st3"], "InGame2")
if not os.path.isfile("GameOver.wav"): if not os.path.isfile("GameOver.mp3"):
dl_vid("https://youtu.be/J_3Zad-e9f4", "GameOver") dl_vid("https://youtu.be/J_3Zad-e9f4", "GameOver", "mp3")

View File

@ -0,0 +1,10 @@
namespace testexetrisathlon
{
public static class SizeSetter
{
public static void SetWindowSize(int width, int height)
{
}
}
}

View File

@ -1,24 +0,0 @@
using System;
using System.Linq;
namespace testexetrisathlon
{
internal static class OSCheck
{
private static bool _checkedWindows;
private static bool _isWindows;
public static bool IsWindows
{
get
{
if (_checkedWindows) return _isWindows;
_isWindows =
new[] {PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT, PlatformID.WinCE}
.Contains(Environment.OSVersion.Platform);
_checkedWindows = true;
return _isWindows;
}
}
}
}

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading;
using testexetrisathlon.SoundManagement; using testexetrisathlon.SoundManagement;
using static System.Console; using static System.Console;
@ -51,7 +50,8 @@ namespace testexetrisathlon
public static bool Debug; public static bool Debug;
public static readonly Random Rnd = new Random(); public static readonly Random Rnd = new Random();
private static ISoundManager soundManager; private static ISoundManager _soundManager;
public static IBeeper Beeper;
private static string InGame => SettingsMan.UsingAltTrack ? "InGame2" : "InGame1"; private static string InGame => SettingsMan.UsingAltTrack ? "InGame2" : "InGame1";
#if DEBUG #if DEBUG
@ -63,22 +63,20 @@ namespace testexetrisathlon
{ {
Debug = args.Contains("debug"); Debug = args.Contains("debug");
#endif #endif
Beeper = new Beeper();
BackgroundColor = ConsoleColor.Red; BackgroundColor = ConsoleColor.Red;
ForegroundColor = ConsoleColor.Yellow; ForegroundColor = ConsoleColor.Yellow;
soundManager = OSCheck.IsWindows ? (ISoundManager) new WindowsSoundManager() : new LinuxSoundManager(); _soundManager = new SoundManager();
soundManager.Init(new Dictionary<string, string> _soundManager.Init(new Dictionary<string, string>
{ {
{"Intro", "testexetrisathlon.Intro.wav"}, {"Intro", "testexetrisathlon.Intro.mp3"},
{"InGame1", "testexetrisathlon.InGame1.wav"}, {"InGame1", "testexetrisathlon.InGame1.mp3"},
{"InGame2", "testexetrisathlon.InGame2.wav"}, {"InGame2", "testexetrisathlon.InGame2.mp3"},
{"GameOver", "testexetrisathlon.GameOver.wav"} {"GameOver", "testexetrisathlon.GameOver.mp3"}
}); });
if (OSCheck.IsWindows) SizeSetter.SetWindowSize(42, 29);
{ if (Debug)
SetWindowSize(42, 29); SizeSetter.SetWindowSize(50, 40);
if (Debug)
SetWindowSize(50, 40);
}
SetCursorPosition(0, 0); SetCursorPosition(0, 0);
bool playing = true; bool playing = true;
GameState state = GameState.Menu; GameState state = GameState.Menu;
@ -89,7 +87,7 @@ namespace testexetrisathlon
{ {
case GameState.Menu: case GameState.Menu:
Clear(); Clear();
soundManager.SetCurrent(Intro); _soundManager.SetCurrent(Intro);
DrawSymbol(); DrawSymbol();
SetCursorPosition(12, 18); SetCursorPosition(12, 18);
Write("HighScore: " + SettingsMan.HighScore); Write("HighScore: " + SettingsMan.HighScore);
@ -124,7 +122,7 @@ namespace testexetrisathlon
} }
break; break;
case GameState.Game: case GameState.Game:
soundManager.SetCurrent(InGame); _soundManager.SetCurrent(InGame);
_dropTimer.Start(); _dropTimer.Start();
SetCursorPosition(25, 0); SetCursorPosition(25, 0);
WriteLine("Level " + _level); WriteLine("Level " + _level);
@ -143,7 +141,7 @@ namespace testexetrisathlon
break; break;
case GameState.GameOver: case GameState.GameOver:
SettingsMan.HighScore = _score; SettingsMan.HighScore = _score;
soundManager.SetCurrent(GameOver); _soundManager.SetCurrent(GameOver);
string input = ""; string input = "";
while (input != "y" && input != "n") while (input != "y" && input != "n")
{ {
@ -179,7 +177,7 @@ namespace testexetrisathlon
} }
finally finally
{ {
soundManager.Dispose(); _soundManager.Dispose();
} }
BackgroundColor = Colors[0]; BackgroundColor = Colors[0];
ForegroundColor = Colors[1]; ForegroundColor = Colors[1];
@ -262,7 +260,7 @@ namespace testexetrisathlon
} }
break; break;
} }
soundManager.SetVolume(SettingsMan.Volume * 10); _soundManager.SetVolume(SettingsMan.Volume * 10);
} }
} }

View File

@ -0,0 +1,9 @@
using System;
namespace testexetrisathlon.SoundManagement
{
public interface IBeeper : IDisposable
{
public void Beep(int frequency, int duration);
}
}

View File

@ -5,28 +5,23 @@ using Bassoon;
namespace testexetrisathlon.SoundManagement namespace testexetrisathlon.SoundManagement
{ {
public static class Beeper public class Beeper : IBeeper
{ {
private static readonly Dictionary<Tuple<int, int>, Tuple<string, Sound>> Beeps = new Dictionary<Tuple<int, int>, Tuple<string, Sound>>(); private static readonly Dictionary<Tuple<int, int>, Tuple<string, Sound>> Beeps = new Dictionary<Tuple<int, int>, Tuple<string, Sound>>();
public static void Beep(int frequency, int duration) public void Beep(int frequency, int duration)
{ {
if (OSCheck.IsWindows) Tuple<int, int> key = new Tuple<int, int>(frequency, duration);
Console.Beep(frequency, duration); if (!Beeps.ContainsKey(key))
else
{ {
Tuple<int, int> key = new Tuple<int, int>(frequency, duration); string file = Path.GetTempFileName();
if (!Beeps.ContainsKey(key)) File.Move(file, Path.ChangeExtension(file, "wav"));
{ file = Path.ChangeExtension(file, "wav");
string file = Path.GetTempFileName(); File.WriteAllBytes(file, BeepBeep(1000, frequency, duration));
File.Move(file, Path.ChangeExtension(file, "wav")); Beeps.Add(key, new Tuple<string, Sound>(file, new Sound(file)));
file = Path.ChangeExtension(file, "wav");
File.WriteAllBytes(file, BeepBeep(1000, frequency, duration));
Beeps.Add(key, new Tuple<string, Sound>(file, new Sound(file)));
}
Beeps[key].Item2.Cursor = 0;
Beeps[key].Item2.Play();
Console.Clear();
} }
Beeps[key].Item2.Cursor = 0;
Beeps[key].Item2.Play();
Console.Clear();
} }
private static byte[] BeepBeep(int amplitude, int frequency, int duration) private static byte[] BeepBeep(int amplitude, int frequency, int duration)
@ -51,10 +46,9 @@ namespace testexetrisathlon.SoundManagement
return ms.ToArray(); return ms.ToArray();
} }
public static void Dispose() public void Dispose()
{ {
if (OSCheck.IsWindows) foreach (Tuple<string, Sound> file in Beeps.Values) File.Delete(file.Item1);
foreach (Tuple<string, Sound> file in Beeps.Values) File.Delete(file.Item1);
} }
} }
} }

View File

@ -6,7 +6,7 @@ using Bassoon;
namespace testexetrisathlon.SoundManagement namespace testexetrisathlon.SoundManagement
{ {
public class LinuxSoundManager : ISoundManager public class SoundManager : ISoundManager
{ {
private BassoonEngine _bassoon; private BassoonEngine _bassoon;
private Dictionary<string, Sound> _loadedSounds; private Dictionary<string, Sound> _loadedSounds;

View File

@ -0,0 +1,12 @@
using System;
namespace testexetrisathlon.SoundManagement
{
public class Beeper : IBeeper
{
public void Beep(int frequency, int duration) => Console.Beep(frequency, duration);
public void Dispose()
{
}
}
}

View File

@ -1,11 +1,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using NAudio.Wave; using NAudio.Wave;
namespace testexetrisathlon.SoundManagement namespace testexetrisathlon.SoundManagement
{ {
public sealed class WindowsSoundManager : ISoundManager public sealed class SoundManager : ISoundManager
{ {
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
private WaveStream _current; private WaveStream _current;
@ -17,7 +18,7 @@ namespace testexetrisathlon.SoundManagement
{ {
_output = new WaveOutEvent(); _output = new WaveOutEvent();
_loadedSounds = manifestResources.ToDictionary(s => s.Key, _loadedSounds = manifestResources.ToDictionary(s => s.Key,
s => new LoopStream(new WaveFileReader(Assembly.GetManifestResourceStream(s.Value)))); s => new LoopStream(new WaveFileReader(Mp3ToWav(Assembly.GetManifestResourceStream(s.Value)))));
} }
public void SetCurrent(string id) public void SetCurrent(string id)
@ -39,5 +40,15 @@ namespace testexetrisathlon.SoundManagement
foreach (LoopStream reader in _loadedSounds.Values) reader.Dispose(); foreach (LoopStream reader in _loadedSounds.Values) reader.Dispose();
_output.Dispose(); _output.Dispose();
} }
private static MemoryStream Mp3ToWav(Stream mp3File)
{
using Mp3FileReader reader = new Mp3FileReader(mp3File);
using WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader);
MemoryStream ms = new MemoryStream();
WaveFileWriter.WriteWavFileToStream(ms, pcmStream);
ms.Position = 0;
return ms;
}
} }
} }

View File

@ -86,7 +86,7 @@ namespace testexetrisathlon
{ {
Location.ForEach(s => Program.DroppedTetrominoeLocationGrid[s[0], s[1]] = 1); Location.ForEach(s => Program.DroppedTetrominoeLocationGrid[s[0], s[1]] = 1);
Program.IsDropped = true; Program.IsDropped = true;
Beeper.Beep(800, 200); Program.Beeper.Beep(800, 200);
} }
else else
{ {

View File

@ -0,0 +1,9 @@
using System;
namespace testexetrisathlon
{
public static class SizeSetter
{
public static void SetWindowSize(int width, int height) => Console.SetWindowSize(width, height);
}
}

View File

@ -8,7 +8,7 @@
<Deterministic>false</Deterministic> <Deterministic>false</Deterministic>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT' "> <PostBuildEvent Condition="'$(OS)' == 'Windows_NT'">
if exist "$(SolutionDir)Data\pkgtool.exe" ($(SolutionDir)Data\pkgtool.exe build --noLogo --binDir .) else if exist "%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" ("%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" build --noLogo --binDir .) else echo Cound not find Package build tools, skipping if exist "$(SolutionDir)Data\pkgtool.exe" ($(SolutionDir)Data\pkgtool.exe build --noLogo --binDir .) else if exist "%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" ("%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" build --noLogo --binDir .) else echo Cound not find Package build tools, skipping
</PostBuildEvent> </PostBuildEvent>
<PostBuildEvent Condition="'$(OS)' != 'Windows_NT'"> <PostBuildEvent Condition="'$(OS)' != 'Windows_NT'">
@ -19,16 +19,20 @@
<ApplicationIcon>tetris_yUxH6t_256px.ico</ApplicationIcon> <ApplicationIcon>tetris_yUxH6t_256px.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Intro.wav" /> <EmbeddedResource Include="GameOver.mp3" />
</ItemGroup> <EmbeddedResource Include="InGame1.mp3" />
<ItemGroup> <EmbeddedResource Include="InGame2.mp3" />
<EmbeddedResource Include="GameOver.wav" /> <EmbeddedResource Include="Intro.mp3" />
<EmbeddedResource Include="InGame1.wav" />
<EmbeddedResource Include="InGame2.wav" />
<Content Include="tetris_yUxH6t_256px.ico" /> <Content Include="tetris_yUxH6t_256px.ico" />
<Compile Remove="SoundManagement/LinuxSoundManager.cs" Condition="'$(OS)' == 'Windows_NT'" />
<Compile Remove="SoundManagement/WindowsSoundManager.cs" Condition="'$(OS)' != 'Windows_NT'" />
<Compile Remove="SoundManagement/LinuxBeeper.cs" Condition="'$(OS)' == 'Windows_NT'" />
<Compile Remove="SoundManagement/WindowsBeeper.cs" Condition="'$(OS)' != 'Windows_NT'" />
<Compile Remove="LinuxSizeSetter.cs" Condition="'$(OS)' == 'Windows_NT'" />
<Compile Remove="WindowsSizeSetter.cs" Condition="'$(OS)' != 'Windows_NT'" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Bassoon" Version="1.1.1" /> <PackageReference Include="Bassoon" Version="1.1.1" Condition="'$(OS)' != 'Windows_NT'" />
<PackageReference Include="NAudio" Version="1.10.0" /> <PackageReference Include="NAudio" Version="1.10.0" Condition="'$(OS)' == 'Windows_NT'" />
</ItemGroup> </ItemGroup>
</Project> </Project>