Skip to content

Commit

Permalink
Return of tetris
Browse files Browse the repository at this point in the history
  • Loading branch information
Critical-Impact committed Jul 13, 2024
1 parent f1b1784 commit 66cd4b2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
67 changes: 41 additions & 26 deletions InventoryTools/Misc/TetrisGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public TetrisGame(ILogger<TetrisGame> logger, MediatorService mediatorService) :
private int _timerCounter = 0;
private readonly int _timerStep = 10;

public Game Game;
public Game? Game;
private Timer? _gameTimer;


Expand Down Expand Up @@ -75,43 +75,53 @@ private bool isKeyPressed(VirtualKey[] keys) {

private void FrameworkOnOnUpdateEvent(IFramework framework) {
try {
if (Game.Status != Game.GameStatus.InProgress) return;
if (Game != null && Game.Status != Game.GameStatus.InProgress) return;

if (lastMoveTime != null && lastMoveTime.Value.AddMilliseconds(100) >= DateTime.Now)
{
Service.KeyState.ClearAll();
return;
}
}

if (isKeyPressed(new[]{VirtualKey.Z})) {
Game.RotateLeft();
lastMoveTime = DateTime.Now;
}
if (Game != null)
{
if (isKeyPressed(new[] { VirtualKey.Z }))
{
Game.RotateLeft();
lastMoveTime = DateTime.Now;
}

if (isKeyPressed(new[]{VirtualKey.X})) {
Game.RotateRight();
lastMoveTime = DateTime.Now;
}
if (isKeyPressed(new[] { VirtualKey.X }))
{
Game.RotateRight();
lastMoveTime = DateTime.Now;
}

if (isKeyPressed(new[]{VirtualKey.UP})) {
Game.SmashDown();
lastMoveTime = DateTime.Now;
}
if (isKeyPressed(new[] { VirtualKey.UP }))
{
Game.SmashDown();
lastMoveTime = DateTime.Now;
}

if (isKeyPressed(new[]{VirtualKey.DOWN})) {
Game.MoveDown();
lastMoveTime = DateTime.Now;
}
if (isKeyPressed(new[] { VirtualKey.DOWN }))
{
Game.MoveDown();
lastMoveTime = DateTime.Now;
}

if (isKeyPressed(new[]{VirtualKey.LEFT})) {
Game.MoveLeft();
lastMoveTime = DateTime.Now;
}
if (isKeyPressed(new[] { VirtualKey.LEFT }))
{
Game.MoveLeft();
lastMoveTime = DateTime.Now;
}

if (isKeyPressed(new[]{VirtualKey.RIGHT})) {
Game.MoveRight();
lastMoveTime = DateTime.Now;
if (isKeyPressed(new[] { VirtualKey.RIGHT }))
{
Game.MoveRight();
lastMoveTime = DateTime.Now;
}
}

MediatorService.Publish(new OverlaysRequestRefreshMessage());
Service.KeyState.ClearAll();

Expand Down Expand Up @@ -153,6 +163,11 @@ public void DisableTetris()

private void OnTimedEvent(object? source, ElapsedEventArgs e)
{
if (Game == null)
{
return;
}

if (Game.Status != Game.GameStatus.Finished)
{
if (Game.Status != Game.GameStatus.Paused)
Expand Down
2 changes: 1 addition & 1 deletion InventoryTools/Overlays/TetrisOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public TetrisOverlay(ILogger<TetrisOverlay> logger, AtkInventoryExpansion overla

public override bool Draw()
{
if (!HasState || !AtkOverlay.HasAddon)
if (!HasState || !AtkOverlay.HasAddon || !Enabled || _tetrisGame.Game == null)
{
return false;
}
Expand Down
1 change: 1 addition & 0 deletions InventoryTools/Ui/Windows/ConfigurationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public override void Initialize()
_configPages.Add(_settingPageFactory.Invoke(SettingCategory.MobSpawnTracker));
_configPages.Add(_settingPageFactory.Invoke(SettingCategory.TitleMenuButtons));
_configPages.Add(_settingPageFactory.Invoke(SettingCategory.History));
_configPages.Add(_settingPageFactory.Invoke(SettingCategory.Misc));
_configPages.Add(new SeparatorPageItem("Data", true));
_configPages.Add(_configPageFactory.Invoke(typeof(FiltersPage)));
_configPages.Add(_configPageFactory.Invoke(typeof(CraftFiltersPage)));
Expand Down
10 changes: 10 additions & 0 deletions InventoryTools/Ui/Windows/TetrisWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,23 @@ public override void Draw()
if (_tetrisGame.TetrisEnabled)
{
_tetrisOverlay.Enabled = false;
_tetrisOverlay.Clear();
}
else
{
if (_tetrisGame.Game == null)
{
_tetrisGame.Restart();
}
_tetrisOverlay.Enabled = true;
}
_tetrisGame.ToggleTetris();
}

if (tetrisGame == null)
{
return;
}

ImGui.TextUnformatted("Overlay: " + (_tetrisGame.TetrisEnabled ? "Enabled" : "Disabled"));
ImGui.TextUnformatted("Current Status: " + tetrisGame.Status.ToString());
Expand Down

0 comments on commit 66cd4b2

Please sign in to comment.