diff --git a/MLEM.Data/DataTextureAtlas.cs b/MLEM.Data/DataTextureAtlas.cs index 2c64a6c..e311b3b 100644 --- a/MLEM.Data/DataTextureAtlas.cs +++ b/MLEM.Data/DataTextureAtlas.cs @@ -56,23 +56,33 @@ namespace MLEM.Data { text = reader.ReadToEnd(); var atlas = new DataTextureAtlas(texture); - // parse each texture region: " loc piv " - const string regex = @"(.+)\W+loc\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)\W+(?:piv\W+([0-9.]+)\W+([0-9.]+))?"; - foreach (Match match in Regex.Matches(text, regex)) { + // parse each texture region: " loc piv " followed by extra data in the form "key " + foreach (Match match in Regex.Matches(text, @"(.+)\W+loc\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)(?:\W+piv\W+([0-9.]+)\W+([0-9.]+))?(?:\W+(\w+)\W+([0-9.]+)\W+([0-9.]+))*")) { var name = match.Groups[1].Value.Trim(); + // location var loc = new Rectangle( int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value), int.Parse(match.Groups[4].Value), int.Parse(match.Groups[5].Value)); + // pivot var piv = Vector2.Zero; if (match.Groups[6].Success) { piv = new Vector2( float.Parse(match.Groups[6].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.X), float.Parse(match.Groups[7].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.Y)); } - atlas.regions.Add(name, new TextureRegion(texture, loc) { + var region = new TextureRegion(texture, loc) { PivotPixels = piv, Name = name - }); + }; + // additional data + if (match.Groups[8].Success) { + for (var i = 0; i < match.Groups[8].Captures.Count; i++) { + region.SetData(match.Groups[8].Captures[i].Value, new Vector2( + float.Parse(match.Groups[9].Captures[i].Value), + float.Parse(match.Groups[10].Captures[i].Value))); + } + } + atlas.regions.Add(name, region); } return atlas; diff --git a/Sandbox/Content/Textures/Furniture.atlas b/Sandbox/Content/Textures/Furniture.atlas index 9bc74c8..c777c94 100644 --- a/Sandbox/Content/Textures/Furniture.atlas +++ b/Sandbox/Content/Textures/Furniture.atlas @@ -11,6 +11,9 @@ loc 96 0 16 32 LongTableUp loc 0 32 64 48 piv 16 48 +extraData1 12 14 +extraData2 129 4 + LongTableRight loc 64 32 64 48 piv 112 48 \ No newline at end of file diff --git a/Sandbox/GameImpl.cs b/Sandbox/GameImpl.cs index 1391cfe..fd56602 100644 --- a/Sandbox/GameImpl.cs +++ b/Sandbox/GameImpl.cs @@ -157,6 +157,8 @@ namespace Sandbox { var atlas = this.Content.LoadTextureAtlas("Textures/Furniture"); foreach (var r in atlas.Regions) { Console.WriteLine(r.Name + ": " + r.U + " " + r.V + " " + r.Width + " " + r.Height + " " + r.PivotPixels); + foreach (var key in r.GetDataKeys()) + Console.WriteLine(key + " " + r.GetData(key)); } this.OnDraw += (g, time) => { @@ -181,7 +183,7 @@ namespace Sandbox { this.tokenized.Update(time); }; - var testPanel = new Panel(Anchor.Center, new Vector2(0.5F, 100), Vector2.Zero); + /*var testPanel = new Panel(Anchor.Center, new Vector2(0.5F, 100), Vector2.Zero); testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(0.25F, -1))); testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(2500, 1)) {PreventParentSpill = true}); this.UiSystem.Add("Test", testPanel); @@ -192,7 +194,7 @@ namespace Sandbox { }; invalidPanel.AddChild(new Paragraph(Anchor.AutoRight, 1, "This is some test text!", true)); invalidPanel.AddChild(new VerticalSpace(1)); - this.UiSystem.Add("Invalid", invalidPanel); + this.UiSystem.Add("Invalid", invalidPanel);*/ } protected override void DoUpdate(GameTime gameTime) {