Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
Support scaling sprite groups as if they were one sprite, in multiple dimensions.
Support recoloring groups of sprites
Experimental Clipping Sprite support
- 1.1.0
Reduced runtime memory allocation when rendering drawables.
Replaced inefficient LINQ query calls with more performant for and foreach loops.
Adjusted documentation and legal notices to correctly refer to the project as Sprite Compositor (instead of Composer)
Fix documentation links leading nowhere in some contexts
Replaced Angle's inefficient Degrees getter with a more performant syntax
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

An API wrapper that supports composing new sprites from multiple existing ones.

- [Source Code](./src)
- [Demo Project](../SpriteCompositor.Demo/Program.cs)
- [Tests](../SpriteCompositor.Test)
- [Source Code](https://github.com/malforge/mdk2-packages/tree/main/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/src)
- [Demo Project](https://github.com/malforge/mdk2-packages/blob/main/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/Program.cs)
- [Tests](https://github.com/malforge/mdk2-packages/tree/main/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Test)

## Usage

Expand All @@ -16,7 +16,7 @@ All sprites and sprite groups implement the `Sprite` interface, which you can us
`Scale()` a sprite after instantiation, among other things. Individual Sprite types may have additional properties and
methods available, like `TextureSprite`'s `Mirror()` functions.

See the [demo project](../SpriteCompositor.Demo/Program.cs) for a detailed example.
See the [demo project](https://github.com/malforge/mdk2-packages/blob/main/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/SpriteCompositor.Demo/Program.cs) for a detailed example.

### Grouping Sprites

Expand Down Expand Up @@ -84,7 +84,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

### License
You can find a copy of the [GNU General Public License](./COPYING) and [GNU Lesser General Public License](./COPYING.LESSER) next to this source code in COPYING and COPYING.LESSER respectively.
You can find a copy of the [GNU General Public License](https://github.com/malforge/mdk2-packages/blob/main/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/COPYING) and [GNU Lesser General Public License](https://github.com/malforge/mdk2-packages/blob/main/libraries/Lelebees.MdkScriptMixin.SpriteCompositor/Lelebees.MdkScriptMixin.SpriteCompositor/COPYING.LESSER) next to this source code in COPYING and COPYING.LESSER respectively.

### Reaching out
You can reach me as @lelebees on Discord, or through the project's [Github Repository](https://github.com/Lelebees/mdk2-packages-sprite-compositor). Please note while reaching out on Discord that I generally do not accept random friend requests. @Mention me in the [programmable block channel](https://discord.com/channels/125011928711036928/216219467959500800) of the Keen Software House Discord Server to get a hold of me.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Copyright (c) 2026 Lelebees
This file is part of Sprite Composer.
This file is part of Sprite Compositor.

Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
Sprite Compositor is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

Sprite Composer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Sprite Compositor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Sprite Composer.
You should have received a copy of the GNU Lesser General Public License along with Sprite Compositor.
If not, see <https://www.gnu.org/licenses/>. */

using VRageMath;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Copyright (c) 2026 Lelebees
This file is part of Sprite Composer.
This file is part of Sprite Compositor.

Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
Sprite Compositor is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

Sprite Composer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Sprite Compositor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Sprite Composer.
You should have received a copy of the GNU Lesser General Public License along with Sprite Compositor.
If not, see <https://www.gnu.org/licenses/>. */

using VRageMath;
Expand All @@ -26,9 +26,6 @@ public PointAnchor(Vector2 position)

public PointAnchor(float x, float y) : this(new Vector2(x, y)) {}

public Vector2 GetPosition()
{
return position;
}
public Vector2 GetPosition() => position;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Copyright (c) 2026 Lelebees
This file is part of Sprite Composer.
This file is part of Sprite Compositor.

Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
Sprite Compositor is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

Sprite Composer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Sprite Compositor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Sprite Composer.
You should have received a copy of the GNU Lesser General Public License along with Sprite Compositor.
If not, see <https://www.gnu.org/licenses/>. */

using System;
Expand Down Expand Up @@ -51,7 +51,10 @@ private Angle(double radians)
/// <summary>
/// This angle expressed in degrees, positive or negative, limited to one full rotation (0 to 360)
/// </summary>
public double Degrees => Radians * 180 / Math.PI;
public double Degrees
{
get { return Radians * 180 / Math.PI; }
}

public static Angle FromDegrees(double degrees) => new Angle(degrees * Math.PI / 180);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Copyright (c) 2026 Lelebees
This file is part of Sprite Composer.
This file is part of Sprite Compositor.

Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
Sprite Compositor is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

Sprite Composer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Sprite Compositor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Sprite Composer.
You should have received a copy of the GNU Lesser General Public License along with Sprite Compositor.
If not, see <https://www.gnu.org/licenses/>. */

using VRage.Game.GUI.TextPanel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/* Copyright (c) 2026 Lelebees
This file is part of Sprite Composer.
This file is part of Sprite Compositor.

Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
Sprite Compositor is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

Sprite Composer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Sprite Compositor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Sprite Composer.
You should have received a copy of the GNU Lesser General Public License along with Sprite Compositor.
If not, see <https://www.gnu.org/licenses/>. */

using System.Collections.Generic;
using System.Linq;
using VRage.Game.GUI.TextPanel;
using VRageMath;

Expand All @@ -23,17 +22,27 @@ public abstract class SpriteGroup : Sprite
public Vector2 GetPosition()
{
var children = GetChildren();
return children.Aggregate(Vector2.Zero, (current, child) => current + child.GetPosition()) / children.Count;
Vector2 result = Vector2.Zero;
foreach (var child in children) result += child.GetPosition();
return result / children.Count;
}

public void Translate(Vector2 vector) => GetChildren().ForEach(sprite => sprite.Translate(vector));
public void Translate(Vector2 vector)
{
foreach (var sprite in GetChildren()) sprite.Translate(vector);
}

public void Translate(float x, float y) => Translate(new Vector2(x, y));

public void SetColor(Color color) => GetChildren().ForEach(sprite => sprite.SetColor(color));
public void SetColor(Color color)
{
foreach (var sprite in GetChildren()) sprite.SetColor(color);
}

public void SetAlignment(TextAlignment alignment) =>
GetChildren().ForEach(sprite => sprite.SetAlignment(alignment));
public void SetAlignment(TextAlignment alignment)
{
foreach (var sprite in GetChildren()) sprite.SetAlignment(alignment);
}

public void Scale(float scalar, Anchor anchor = null) => Scale(new Vector2(scalar, scalar), anchor);

Expand All @@ -49,7 +58,7 @@ public void Scale(Vector2 scalar, Anchor anchor = null)
anchor = new PointAnchor(anchor.GetPosition());
}

GetChildren().ForEach(sprite => sprite.Scale(scalar, anchor));
foreach (var sprite in GetChildren()) sprite.Scale(scalar, anchor);
}

public void Mirror(Anchor anchor = null) => Scale(new Vector2(-1, -1), anchor);
Expand All @@ -67,20 +76,36 @@ public void Rotate(Angle angle, Anchor positionAnchor = null)
{
positionAnchor = new PointAnchor(GetPosition());
}
if (positionAnchor is SpriteGroup)
else if (positionAnchor is SpriteGroup)
{
positionAnchor = new PointAnchor(positionAnchor.GetPosition());
}
GetChildren().ForEach(sprite => sprite.Rotate(angle, positionAnchor));

foreach (var sprite in GetChildren())
{
sprite.Rotate(angle, positionAnchor);
}
}

public abstract Sprite Clone();

public MySprite[] AsDrawableCollection(RectangleF viewport) =>
GetChildren().SelectMany(child => child.AsDrawableCollection(viewport)).ToArray();
public MySprite[] AsDrawableCollection(RectangleF viewport)
{
List<MySprite> list = new List<MySprite>();
foreach (Sprite child in GetChildren())
foreach (MySprite sprite in child.AsDrawableCollection(viewport))
list.Add(sprite);
return list.ToArray();
}

public MySprite[] AsDrawableCollection() =>
GetChildren().SelectMany(child => child.AsDrawableCollection()).ToArray();
public MySprite[] AsDrawableCollection()
{
List<MySprite> list = new List<MySprite>();
foreach (Sprite child in GetChildren())
foreach (MySprite sprite in child.AsDrawableCollection())
list.Add(sprite);
return list.ToArray();
}

protected abstract List<Sprite> GetChildren();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Copyright (c) 2026 Lelebees
This file is part of Sprite Composer.
This file is part of Sprite Compositor.

Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
Sprite Compositor is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

Sprite Composer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Sprite Compositor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Sprite Composer.
You should have received a copy of the GNU Lesser General Public License along with Sprite Compositor.
If not, see <https://www.gnu.org/licenses/>. */

using System;
Expand All @@ -20,6 +20,7 @@ namespace IngameScript
public abstract class SpriteLeaf : Sprite
{
protected MySprite Sprite;
private readonly MySprite[] drawable;

public Vector2? Position
{
Expand All @@ -30,12 +31,10 @@ public Vector2? Position
protected SpriteLeaf(MySprite sprite)
{
Sprite = sprite;
drawable = new[] { Sprite };
}

public Vector2 GetPosition()
{
return Sprite.Position ?? Vector2.Zero;
}
public Vector2 GetPosition() => Sprite.Position ?? Vector2.Zero;

public void Translate(Vector2 vector)
{
Expand All @@ -45,20 +44,11 @@ public void Translate(Vector2 vector)
Sprite.Position = position;
}

public void Translate(float x, float y)
{
Translate(new Vector2(x, y));
}
public void Translate(float x, float y) => Translate(new Vector2(x, y));

public void SetColor(Color color)
{
Sprite.Color = color;
}
public void SetColor(Color color) => Sprite.Color = color;

public void SetAlignment(TextAlignment alignment)
{
Sprite.Alignment = alignment;
}
public void SetAlignment(TextAlignment alignment) => Sprite.Alignment = alignment;

public virtual void Scale(float scalar, Anchor anchor = null) => Scale(new Vector2(scalar, scalar), anchor);

Expand Down Expand Up @@ -92,23 +82,15 @@ public virtual void Rotate(Angle angle, Anchor positionAnchor = null)

public MySprite[] AsDrawableCollection(RectangleF viewport)
{
return new[]
{
new MySprite(
Sprite.Type,
Sprite.Data,
Sprite.Position + viewport.Center,
Sprite.Size,
Sprite.Color,
Sprite.FontId,
Sprite.Alignment,
Sprite.RotationOrScale)
};
drawable[0] = Sprite;
drawable[0].Position += viewport.Center;
return drawable;
}

public MySprite[] AsDrawableCollection()
{
return new[] { Sprite };
drawable[0] = Sprite;
return drawable;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Copyright (c) 2026 Lelebees
This file is part of Sprite Composer.
This file is part of Sprite Compositor.

Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
Sprite Compositor is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

Sprite Composer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Sprite Compositor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Sprite Composer.
You should have received a copy of the GNU Lesser General Public License along with Sprite Compositor.
If not, see <https://www.gnu.org/licenses/>. */

using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Copyright (c) 2026 Lelebees
This file is part of Sprite Composer.
This file is part of Sprite Compositor.

Sprite Composer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
Sprite Compositor is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

Sprite Composer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Sprite Compositor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Sprite Composer.
You should have received a copy of the GNU Lesser General Public License along with Sprite Compositor.
If not, see <https://www.gnu.org/licenses/>. */
namespace IngameScript
{
Expand Down
Loading
Loading