Skip to content

Commit

Permalink
allow rotating sprites with the 'R' key
Browse files Browse the repository at this point in the history
  • Loading branch information
saint11 committed Dec 24, 2024
1 parent 35c3a14 commit 1318ca3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Murder.Editor/Architect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ protected override void Initialize()
Instance = this;

_playerInput.Register(MurderInputAxis.EditorCamera,
new InputButtonAxis(Keys.W, Keys.A, Keys.S, Keys.D),
new InputButtonAxis(Keys.Up, Keys.Left, Keys.Down, Keys.Right));
new InputButtonAxis(Keys.W, Keys.A, Keys.S, Keys.D));

ImGuiRenderer = new ImGuiRenderer(this);
ImGuiRenderer.RebuildFontAtlas();
Expand Down
2 changes: 1 addition & 1 deletion src/Murder.Editor/Systems/EditorCameraControllerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Update(Context context)
{
// Handled by ImGui
}
else if (!Game.Input.Down(Keys.LeftControl) && noEntitiesSelected)
else if (!Game.Input.Down(Keys.LeftControl))
{
Vector2 cameraMovement = Architect.Input.GetAxis(MurderInputAxis.EditorCamera).Value * Game.DeltaTime * Architect.EditorSettings.WasdCameraSpeed * Math.Clamp((1f / hook.CurrentZoomLevel), .75f, 10f);
if (Game.Input.Down(Keys.LeftShift))
Expand Down
23 changes: 23 additions & 0 deletions src/Murder.Editor/Systems/EntitiesShortcutsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using Bang.Contexts;
using Bang.Entities;
using Bang.Systems;
using Murder.Components;
using Murder.Components.Graphics;
using Murder.Core.Graphics;
using Murder.Editor.Attributes;
using Murder.Editor.Components;
using Murder.Editor.Messages;
using Murder.Helpers;
using Murder.Utilities;

namespace Murder.Editor.Systems;
Expand Down Expand Up @@ -35,6 +37,27 @@ public void Update(Context context)
return;
}

if (Game.Input.Shortcut(Microsoft.Xna.Framework.Input.Keys.R))
{
foreach (var entity in hook.AllSelectedEntities)
{
Direction currentDirection = entity.Value.TryGetFacing()?.Direction ?? Direction.Right;
currentDirection = currentDirection.Rotate90Degrees();
entity.Value.SetFacing(currentDirection);

entity.Value.SendMessage(new AssetUpdatedMessage(typeof(FacingComponent)));

if (entity.Value.TryGetSprite() is SpriteComponent sprite)
{
if (!sprite.RotateWithFacing)
{
entity.Value.SetSprite(sprite with { RotateWithFacing = true });
entity.Value.SendMessage(new AssetUpdatedMessage(typeof(SpriteComponent)));
}
}
}
}

if (Game.Input.Shortcut(Microsoft.Xna.Framework.Input.Keys.H))
{
foreach (var entity in hook.AllSelectedEntities)
Expand Down
2 changes: 1 addition & 1 deletion src/Murder/Components/Graphics/SpriteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Murder.Components
[Tooltip("(0,0) is top left and (1,1) is bottom right"), Slider()]
public readonly Vector2 Offset = Vector2.Zero;

public readonly bool RotateWithFacing = false;
public readonly bool RotateWithFacing { get; init; } = false;
public readonly OutlineStyle HighlightStyle { get; init; } = OutlineStyle.None;

public readonly bool UseUnscaledTime = false;
Expand Down
6 changes: 6 additions & 0 deletions src/Murder/Utilities/DirectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public enum DirectionFlags

public static class DirectionHelper
{
public static Direction Rotate90Degrees(this Direction direction)
{
int newDirection = (int)direction + 2;
return (Direction)newDirection;
}

public static DirectionFlags ToDirectionFlag(this Direction direction)
{
switch (direction)
Expand Down

0 comments on commit 1318ca3

Please sign in to comment.