Skip to content

Commit d860007

Browse files
committed
Added ClipOpt for 2D facets other than effects and emitters.
1 parent f4cfaa7 commit d860007

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

Nu/Nu/World/WorldFacets.fs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ module StaticSpriteFacetExtensions =
3333
member this.GetInsetOpt world : Box2 option = this.Get (nameof this.InsetOpt) world
3434
member this.SetInsetOpt (value : Box2 option) world = this.Set (nameof this.InsetOpt) value world
3535
member this.InsetOpt = lens (nameof this.InsetOpt) this this.GetInsetOpt this.SetInsetOpt
36+
member this.GetClipOpt world : Box2 option = this.Get (nameof this.ClipOpt) world
37+
member this.SetClipOpt (value : Box2 option) world = this.Set (nameof this.ClipOpt) value world
38+
member this.ClipOpt = lens (nameof this.ClipOpt) this this.GetClipOpt this.SetClipOpt
3639
member this.GetStaticImage world : Image AssetTag = this.Get (nameof this.StaticImage) world
3740
member this.SetStaticImage (value : Image AssetTag) world = this.Set (nameof this.StaticImage) value world
3841
member this.StaticImage = lens (nameof this.StaticImage) this this.GetStaticImage this.SetStaticImage
@@ -55,6 +58,7 @@ type StaticSpriteFacet () =
5558

5659
static member Properties =
5760
[define Entity.InsetOpt None
61+
define Entity.ClipOpt None
5862
define Entity.StaticImage Assets.Default.StaticSprite
5963
define Entity.Color Color.One
6064
define Entity.Blend Transparent
@@ -65,7 +69,7 @@ type StaticSpriteFacet () =
6569
let mutable transform = entity.GetTransform world
6670
let staticImage = entity.GetStaticImage world
6771
let insetOpt = match entity.GetInsetOpt world with Some inset -> ValueSome inset | None -> ValueNone
68-
let clipOpt = ValueNone : Box2 voption
72+
let clipOpt = entity.GetClipOpt world |> Option.toValueOption
6973
let color = entity.GetColor world
7074
let blend = entity.GetBlend world
7175
let emission = entity.GetEmission world
@@ -130,6 +134,7 @@ type AnimatedSpriteFacet () =
130134
define Entity.AnimationDelay (GameTime.ofSeconds (1.0f / 15.0f))
131135
define Entity.AnimationStride 1
132136
define Entity.AnimationSheet Assets.Default.AnimatedSprite
137+
define Entity.ClipOpt None
133138
define Entity.Color Color.One
134139
define Entity.Blend Transparent
135140
define Entity.Emission Color.Zero
@@ -143,7 +148,7 @@ type AnimatedSpriteFacet () =
143148
let mutable transform = entity.GetTransform world
144149
let animationSheet = entity.GetAnimationSheet world
145150
let insetOpt = match getSpriteInsetOpt entity world with Some inset -> ValueSome inset | None -> ValueNone
146-
let clipOpt = ValueNone : Box2 voption
151+
let clipOpt = entity.GetClipOpt world |> Option.toValueOption
147152
let color = entity.GetColor world
148153
let blend = entity.GetBlend world
149154
let emission = entity.GetEmission world
@@ -1687,6 +1692,7 @@ type TileMapFacet () =
16871692
define Entity.CollisionCategories "1"
16881693
define Entity.CollisionMask Constants.Physics.CollisionWildcard
16891694
define Entity.PhysicsMotion SynchronizedMotion
1695+
define Entity.ClipOpt None
16901696
define Entity.Color Color.One
16911697
define Entity.Emission Color.Zero
16921698
define Entity.TileLayerClearance 2.0f
@@ -1758,6 +1764,7 @@ type TileMapFacet () =
17581764
viewBounds
17591765
perimeterUnscaled.Min.V2
17601766
transform.Elevation
1767+
(entity.GetClipOpt world |> Option.toValueOption)
17611768
(entity.GetColor world)
17621769
(entity.GetEmission world)
17631770
(entity.GetTileLayerClearance world)
@@ -1792,6 +1799,7 @@ type TmxMapFacet () =
17921799
define Entity.CollisionCategories "1"
17931800
define Entity.CollisionMask Constants.Physics.CollisionWildcard
17941801
define Entity.PhysicsMotion SynchronizedMotion
1802+
define Entity.ClipOpt None
17951803
define Entity.Color Color.One
17961804
define Entity.Emission Color.Zero
17971805
define Entity.TileLayerClearance 2.0f
@@ -1860,6 +1868,7 @@ type TmxMapFacet () =
18601868
viewBounds
18611869
perimeterUnscaled.Min.V2
18621870
transform.Elevation
1871+
(entity.GetClipOpt world |> Option.toValueOption)
18631872
(entity.GetColor world)
18641873
(entity.GetEmission world)
18651874
(entity.GetTileLayerClearance world)

Nu/Nu/World/WorldTmxMap.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ module TmxMap =
328328
BodyIndex = bodyIndex }
329329
bodyProperties
330330

331-
let getLayeredMessages2d time absolute (viewBounds : Box2) (tileMapPosition : Vector2) tileMapElevation tileMapColor tileMapEmission tileLayerClearance tileSizeDivisor tileIndexOffset tileIndexOffsetRange tileMapPackage (tileMap : TmxMap) =
331+
let getLayeredMessages2d time absolute (viewBounds : Box2) (tileMapPosition : Vector2) tileMapElevation tileMapClipOpt tileMapColor tileMapEmission tileLayerClearance tileSizeDivisor tileIndexOffset tileIndexOffsetRange tileMapPackage (tileMap : TmxMap) =
332332
let layers = List.ofSeq tileMap.TileLayers
333333
let tileSourceSize = v2i tileMap.TileWidth tileMap.TileHeight
334334
let tileSizeDivisor = max 1 tileSizeDivisor
@@ -403,7 +403,7 @@ module TmxMap =
403403
RenderOperation2d =
404404
RenderTiles
405405
{ Transform = transform
406-
ClipOpt = ValueNone // TODO: implement clipping for tile maps.
406+
ClipOpt = tileMapClipOpt
407407
Color = tileMapColor
408408
Emission = tileMapEmission
409409
MapSize = Vector2i (tileMap.Width, tileMap.Height)

0 commit comments

Comments
 (0)