Skip to content

Commit

Permalink
feat(Scene): Setup API
Browse files Browse the repository at this point in the history
resolve #3
  • Loading branch information
EbiseLutica committed Jan 22, 2024
1 parent 6d37143 commit 71eb258
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 31 deletions.
16 changes: 8 additions & 8 deletions Promete/Elements/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

namespace Promete.Elements;

public class Container : ElementBase, IEnumerable<ElementBase>
public class Container(
bool isTrimmable = false,
string name = "",
Vector? location = default,
Vector? scale = default,
VectorInt? size = default)
: ElementBase(name, location, scale, size), IEnumerable<ElementBase>
{
public int Count => children.Count;

public ElementBase this[int index] => children[index];

public bool IsTrimmable { get; set; }

public Container()
{
}

public Container(bool isTrimmable) => IsTrimmable = isTrimmable;
public bool IsTrimmable { get; set; } = isTrimmable;

public void Insert(int index, ElementBase item)
{
Expand Down
11 changes: 10 additions & 1 deletion Promete/Elements/ElementBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ public int Height

private readonly List<Component> components = [];

public ElementBase()
public ElementBase(
string name = "",
Vector? location = default,
Vector? scale = default,
VectorInt? size = default
)
{
Name = name;
Location = location ?? (0, 0);
Scale = scale ?? (1, 1);
Size = size ?? (0, 0);
ComputeTransform();
}

Expand Down
17 changes: 8 additions & 9 deletions Promete/Elements/NineSliceSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@

namespace Promete.Elements;

public class NineSliceSprite : ElementBase
public class NineSliceSprite(
Texture9Sliced texture,
Color? tintColor = default,
string name = "",
Vector? location = default,
Vector? scale = default) : ElementBase(name, location, scale, texture.Size)
{
/// <summary>
/// Get or set the texture.
/// </summary>
/// <value></value>
public Texture9Sliced Texture { get; set; }
public Texture9Sliced Texture { get; set; } = texture;

/// <summary>
/// Get or set the tint color.
/// </summary>
/// <value></value>
public Color TintColor { get; set; } = Color.White;

public NineSliceSprite(Texture9Sliced texture)
{
Texture = texture;
base.Size = Texture.Size;
}
public Color TintColor { get; set; } = tintColor ?? Color.White;
}
9 changes: 7 additions & 2 deletions Promete/Elements/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@

namespace Promete.Elements;

public class Sprite(ITexture texture) : ElementBase
public class Sprite(
ITexture texture,
Color? tintColor = default,
string name = "",
Vector? location = default,
Vector? scale = default) : ElementBase(name, location, scale, texture.Size)
{
public ITexture? Texture { get; set; } = texture;

public Color? TintColor { get; set; }
public Color TintColor { get; set; } = tintColor ?? Color.White;

public override VectorInt Size
{
Expand Down
17 changes: 10 additions & 7 deletions Promete/Elements/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,19 @@ public Font Font

private readonly GlyphRenderer glyphRenderer;

public Text(GlyphRenderer glyphRenderer, string content = "") : this(glyphRenderer, content, Font.GetDefault(16))
{
}

public Text(GlyphRenderer glyphRenderer, string content, Font font, Color? color = null)
public Text(
GlyphRenderer glyphRenderer,
string content,
Font? font = default,
Color? color = default,
string name = "",
Vector? location = default,
Vector? scale = default) : base(name, location, scale)
{
this.glyphRenderer = glyphRenderer;
this.content = content;
this.font = font;
textColor = color;
this.font = font ?? Font.GetDefault(16);
textColor = color ?? System.Drawing.Color.White;

RenderTexture();
}
Expand Down
11 changes: 8 additions & 3 deletions Promete/Elements/Tilemap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

namespace Promete.Elements;

public class Tilemap(VectorInt tileSize) : ElementBase
public class Tilemap(VectorInt tileSize,
Color? defaultColor = default,
TilemapRenderingMode renderingMode = TilemapRenderingMode.Auto,
string name = "",
Vector? location = default,
Vector? scale = default) : ElementBase(name, location, scale)
{
/// <summary>
/// Get or set size of grid.
Expand All @@ -15,9 +20,9 @@ public class Tilemap(VectorInt tileSize) : ElementBase
/// <summary>
/// Get or set default tint color of tiles.
/// </summary>
public Color? DefaultColor { get; set; }
public Color? DefaultColor { get; set; } = defaultColor;

public TilemapRenderingMode RenderingMode { get; set; } = TilemapRenderingMode.Auto;
public TilemapRenderingMode RenderingMode { get; set; } = renderingMode;

public IReadOnlyDictionary<VectorInt, (ITile tile, Color? color)> Tiles => tiles.AsReadOnly();

Expand Down
12 changes: 11 additions & 1 deletion Promete/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ namespace Promete;
/// </summary>
public abstract class Scene
{

/// <summary>
/// Get a root container of this scene.
/// </summary>
public Container Root { get; } = new();
public Container Root { get; }
public Scene()
{
Root = Setup();
}

public virtual Container Setup()
{
return [];
}

/// <summary>
/// Called when the scene starts.
Expand Down

0 comments on commit 71eb258

Please sign in to comment.