Skip to content

Commit

Permalink
Implement rudimentary sprite support in fake display
Browse files Browse the repository at this point in the history
  • Loading branch information
baratgabor committed Oct 28, 2020
1 parent f4eb3e7 commit 958fa04
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/GridOS.ConsoleTest/TestFakes/FakeDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IngameScript
{
internal class FakeDisplay : IMyTextSurface
{
public event Action<string> TextWritten;
private List<MySprite> _spritesReceived = new List<MySprite>();

public float FontSize { get; set; }

Expand Down Expand Up @@ -111,5 +113,21 @@ public Vector2 MeasureStringInPixels(StringBuilder text, string font, float scal
Y = fakeCharHeight // Assumes no newlines in text.
};
}

public MySpriteDrawFrame DrawFrame()
{
// TODO: This makes the assumption that 'draw frame' is supposed to be requested only once per frame. Would be more robust to wire some "frame start" notification into this fake class.
_spritesReceived.Clear();

return new MySpriteDrawFrame(
spriteReceiver: (sprite) => _spritesReceived.Add(sprite),

// Simply extract text from text type sprites.
disposeReceiver: () => TextWritten?.Invoke(
string.Join(Environment.NewLine,
_spritesReceived
.Where(s => s.Type == SpriteType.TEXT)
.Select(s => s.Data))));
}
}
}

0 comments on commit 958fa04

Please sign in to comment.