diff --git a/Promete/Elements/Container.cs b/Promete/Elements/Container.cs index 787e6c8..5886d72 100644 --- a/Promete/Elements/Container.cs +++ b/Promete/Elements/Container.cs @@ -3,19 +3,19 @@ namespace Promete.Elements; -public class Container : ElementBase, IEnumerable +public class Container( + bool isTrimmable = false, + string name = "", + Vector? location = default, + Vector? scale = default, + VectorInt? size = default) + : ElementBase(name, location, scale, size), IEnumerable { 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) { diff --git a/Promete/Elements/ElementBase.cs b/Promete/Elements/ElementBase.cs index a984bf6..c88e033 100644 --- a/Promete/Elements/ElementBase.cs +++ b/Promete/Elements/ElementBase.cs @@ -31,8 +31,17 @@ public int Height private readonly List 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(); } diff --git a/Promete/Elements/NineSliceSprite.cs b/Promete/Elements/NineSliceSprite.cs index 9d6cbd6..1145f93 100644 --- a/Promete/Elements/NineSliceSprite.cs +++ b/Promete/Elements/NineSliceSprite.cs @@ -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) { /// /// Get or set the texture. /// /// - public Texture9Sliced Texture { get; set; } + public Texture9Sliced Texture { get; set; } = texture; /// /// Get or set the tint color. /// /// - 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; } diff --git a/Promete/Elements/Sprite.cs b/Promete/Elements/Sprite.cs index 5ff1ea0..5dbd457 100644 --- a/Promete/Elements/Sprite.cs +++ b/Promete/Elements/Sprite.cs @@ -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 { diff --git a/Promete/Elements/Text.cs b/Promete/Elements/Text.cs index ba67dba..8991767 100644 --- a/Promete/Elements/Text.cs +++ b/Promete/Elements/Text.cs @@ -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(); } diff --git a/Promete/Elements/Tilemap.cs b/Promete/Elements/Tilemap.cs index 2c8b177..12a409e 100644 --- a/Promete/Elements/Tilemap.cs +++ b/Promete/Elements/Tilemap.cs @@ -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) { /// /// Get or set size of grid. @@ -15,9 +20,9 @@ public class Tilemap(VectorInt tileSize) : ElementBase /// /// Get or set default tint color of tiles. /// - 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 Tiles => tiles.AsReadOnly(); diff --git a/Promete/Scene.cs b/Promete/Scene.cs index 177b717..170e986 100644 --- a/Promete/Scene.cs +++ b/Promete/Scene.cs @@ -7,10 +7,20 @@ namespace Promete; /// public abstract class Scene { + /// /// Get a root container of this scene. /// - public Container Root { get; } = new(); + public Container Root { get; } + public Scene() + { + Root = Setup(); + } + + public virtual Container Setup() + { + return []; + } /// /// Called when the scene starts.