1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Fixes for default interface properties and bindings

This commit is contained in:
Brian Fiete 2020-11-19 09:37:43 -08:00
parent 4e5baf3b84
commit 4cae7ff373
3 changed files with 146 additions and 96 deletions

View file

@ -101,6 +101,58 @@ namespace Tests
}
}
public struct Rect
{
public float x, y, width, height;
}
public class Component
{
}
public class Hitbox : Component
{
public Rect mArea = .() { x=1, y=2, width=3, height=4, };
}
public interface IEntity
{
public T GetComponent<T>() where T : Component;
}
public interface IHitbox : IEntity
{
public Hitbox HitboxValue { get; set; }
public Hitbox Hitbox
{
get
{
if (HitboxValue == null)
{
HitboxValue = GetComponent<Hitbox>();
}
return HitboxValue;
}
}
}
class GameItem : IEntity, IHitbox
{
public T GetComponent<T>() where T : Component
{
return new T();
}
public Hitbox HitboxValue { get; set; }
}
static Hitbox GetHitbox<T>(T val) where T : IHitbox
{
return val.Hitbox;
}
[Test]
public static void TestBasics()
{
@ -130,6 +182,11 @@ namespace Tests
IFaceA ifa = cba;
Test.Assert(ifa.GetType() == typeof(ClassB));
GameItem gameItem = scope .();
var hitbox = GetHitbox(gameItem);
Test.Assert(hitbox.mArea == .() { x=1, y=2, width=3, height=4 });
delete hitbox;
}
////