mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Trying dispose pattern instead
This commit is contained in:
@@ -60,25 +60,29 @@ public class SlotsCommand : ICommand
|
|||||||
|
|
||||||
Raylib.SetConfigFlags(ConfigFlags.HiddenWindow);
|
Raylib.SetConfigFlags(ConfigFlags.HiddenWindow);
|
||||||
Raylib.InitWindow(500,900,"KiwiSlot");
|
Raylib.InitWindow(500,900,"KiwiSlot");
|
||||||
|
|
||||||
var board = new KiwiSlotBoard(wager);
|
decimal winnings;
|
||||||
board.LoadAssets();
|
string featureAddOn;
|
||||||
board.ExecuteGameLoop();
|
try
|
||||||
//var finalImage = board.GenerateAnimatedWebp(board.SlotFrames);
|
|
||||||
using (var finalImage = board.GenerateAnimatedWebp(board.SlotFrames))
|
|
||||||
{
|
{
|
||||||
board.UnloadAssets(); // beep boop says to more aggressively destroy every frame
|
var board = new KiwiSlotBoard(wager);
|
||||||
|
board.LoadAssets();
|
||||||
|
board.ExecuteGameLoop();
|
||||||
|
using var finalImage = board.GenerateAnimatedWebp(board.SlotFrames);
|
||||||
|
winnings = board.RunningTotalDisplay;
|
||||||
|
featureAddOn = board.GotFeature ? "Congrats on the feature." : "";
|
||||||
|
board.Dispose();
|
||||||
if (finalImage == null) throw new InvalidOperationException("finalimage was null");
|
if (finalImage == null) throw new InvalidOperationException("finalimage was null");
|
||||||
var imageUrl = await Zipline.Upload(finalImage, new MediaTypeHeaderValue("image/webp"), "1h", ctx);
|
var imageUrl = await Zipline.Upload(finalImage, new MediaTypeHeaderValue("image/webp"), "1h", ctx);
|
||||||
if (imageUrl == null) throw new InvalidOperationException("Image failed to upload/failed to get URL");
|
if (imageUrl == null) throw new InvalidOperationException("Image failed to upload/failed to get URL");
|
||||||
await botInstance.SendChatMessageAsync($"[img]{imageUrl}[/img]", true,
|
await botInstance.SendChatMessageAsync($"[img]{imageUrl}[/img]", true,
|
||||||
autoDeleteAfter: TimeSpan.FromMinutes(3));
|
autoDeleteAfter: TimeSpan.FromMinutes(3));
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
board.UnloadAssets();
|
{
|
||||||
Raylib.CloseWindow();
|
Raylib.CloseWindow();
|
||||||
|
}
|
||||||
var winnings = board.RunningTotalDisplay;
|
|
||||||
var colors =
|
var colors =
|
||||||
await SettingsProvider.GetMultipleValuesAsync([
|
await SettingsProvider.GetMultipleValuesAsync([
|
||||||
BuiltIn.Keys.KiwiFarmsGreenColor, BuiltIn.Keys.KiwiFarmsRedColor
|
BuiltIn.Keys.KiwiFarmsGreenColor, BuiltIn.Keys.KiwiFarmsRedColor
|
||||||
@@ -93,8 +97,6 @@ public class SlotsCommand : ICommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if you win
|
|
||||||
var featureAddOn = board.GotFeature ? "Congrats on the feature." : "";
|
|
||||||
winnings -= wager;
|
winnings -= wager;
|
||||||
newBalance = await Money.NewWagerAsync(gambler.Id, wager, winnings, WagerGame.Slots, ct: ctx);
|
newBalance = await Money.NewWagerAsync(gambler.Id, wager, winnings, WagerGame.Slots, ct: ctx);
|
||||||
await botInstance.SendChatMessageAsync(
|
await botInstance.SendChatMessageAsync(
|
||||||
@@ -102,7 +104,7 @@ public class SlotsCommand : ICommand
|
|||||||
$"{featureAddOn}", true, autoDeleteAfter: TimeSpan.FromSeconds(30));
|
$"{featureAddOn}", true, autoDeleteAfter: TimeSpan.FromSeconds(30));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class KiwiSlotBoard
|
private class KiwiSlotBoard : IDisposable
|
||||||
{
|
{
|
||||||
private const char WILD = 'K', FEATURE = 'L', EXPANDER = 'M';
|
private const char WILD = 'K', FEATURE = 'L', EXPANDER = 'M';
|
||||||
public readonly List<Raylib_cs.Image> SlotFrames = [];
|
public readonly List<Raylib_cs.Image> SlotFrames = [];
|
||||||
@@ -175,18 +177,6 @@ public class SlotsCommand : ICommand
|
|||||||
for (var i = 1; i <= 5; i++) _expanderTextures[i] = Raylib.LoadTexture(Path.Combine(assetPath, $"exp{i}.png"));
|
for (var i = 1; i <= 5; i++) _expanderTextures[i] = Raylib.LoadTexture(Path.Combine(assetPath, $"exp{i}.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnloadAssets()
|
|
||||||
{
|
|
||||||
Raylib.UnloadTexture(_headerTexture);
|
|
||||||
foreach (var t in _symbolTextures.Values) Raylib.UnloadTexture(t);
|
|
||||||
foreach (var t in _expanderTextures.Values) Raylib.UnloadTexture(t);
|
|
||||||
foreach (var img in SlotFrames) // claude edited this for some reason
|
|
||||||
{
|
|
||||||
Raylib.UnloadImage(img);
|
|
||||||
}
|
|
||||||
SlotFrames.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ExecuteGameLoop(int featureSpins = 0)
|
public void ExecuteGameLoop(int featureSpins = 0)
|
||||||
{
|
{
|
||||||
if (featureSpins is not 0) GotFeature = true;
|
if (featureSpins is not 0) GotFeature = true;
|
||||||
@@ -527,6 +517,27 @@ public class SlotsCommand : ICommand
|
|||||||
outputStream.Position = 0;
|
outputStream.Position = 0;
|
||||||
return outputStream;
|
return outputStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
foreach (var img in SlotFrames)
|
||||||
|
Raylib.UnloadImage(img);
|
||||||
|
SlotFrames.Clear();
|
||||||
|
|
||||||
|
foreach (var t in _expanderTextures.Values)
|
||||||
|
Raylib.UnloadTexture(t);
|
||||||
|
_expanderTextures.Clear();
|
||||||
|
|
||||||
|
foreach (var t in _symbolTextures.Values)
|
||||||
|
Raylib.UnloadTexture(t);
|
||||||
|
_symbolTextures.Clear();
|
||||||
|
|
||||||
|
if (_headerTexture.Id != 0)
|
||||||
|
{
|
||||||
|
Raylib.UnloadTexture(_headerTexture);
|
||||||
|
_headerTexture = default;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class WinDetail
|
private class WinDetail
|
||||||
|
|||||||
Reference in New Issue
Block a user