more wrappers around bool values

This commit is contained in:
Josh Deprez 2021-08-23 11:10:46 +10:00
parent 94db859faf
commit 1d3327cb1c
8 changed files with 42 additions and 9 deletions

View file

@ -11,10 +11,10 @@ var _ Drawer = &Fill{}
// Fill fills the screen with a colour.
type Fill struct {
Color color.Color
ZOrder
Hidden bool
ID
Color color.Color
Hidden
ZOrder
}
func (f *Fill) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {

View file

@ -23,6 +23,7 @@ func init() {
// Image draws an image at a position.
type Image struct {
ID
Hidden
Parallax
Pos image.Point
Src ImageRef
@ -31,6 +32,9 @@ type Image struct {
// Draw draws the image.
func (i *Image) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
if i.Hidden {
return
}
var geom ebiten.GeoM
geom.Translate(float64(i.Pos.X), float64(i.Pos.Y))
geom.Concat(opts.GeoM)

View file

@ -17,6 +17,13 @@ type Collider interface {
CollidesWith(image.Rectangle) bool
}
// Disabler components can be disabled.
type Disabler interface {
IsDisabled() bool
Disable()
Enable()
}
// Drawer components can draw themselves. Draw is called often.
// Each component is responsible for calling Draw on its child components
// (so that hiding the parent can hide the children, etc).
@ -88,6 +95,7 @@ type Scener interface {
// It seems cleaner to let the engine assert only for the interface it needs at that moment.
Bounder
Disabler
Drawer
DrawOrderer
Hider

View file

@ -14,6 +14,18 @@ type Bounds image.Rectangle
// BoundingRect returns b as an image.Rectangle.
func (b Bounds) BoundingRect() image.Rectangle { return image.Rectangle(b) }
// Disabled implements Disabler directly (as a bool).
type Disabled bool
// IsHidden returns h as a bool.
func (d Disabled) IsDisabled() bool { return bool(d) }
// Hide sets h to true.
func (d *Disabled) Disable() { *d = true }
// Show sets h to false.
func (d *Disabled) Enable() { *d = false }
// Hidden implements Hider directly (as a bool).
type Hidden bool

View file

@ -20,7 +20,7 @@ type Scene struct {
ID
Bounds // world coordinates
Components []interface{}
Disabled bool
Disabled
Hidden
ZOrder
}

View file

@ -56,6 +56,15 @@ func (r *SceneRef) Load(assets fs.FS) error {
// BoundingRect returns the Bounds from the scene.
func (r SceneRef) BoundingRect() image.Rectangle { return r.scene.BoundingRect() }
// IsDisabled returns the value of IsDisabled from the scene.
func (r SceneRef) IsDisabled() bool { return r.scene.IsDisabled() }
// Disable calls Disable on the scene.
func (r SceneRef) Disable() { r.scene.Disable() }
// Enable calls Enable on the scene.
func (r SceneRef) Enable() { r.scene.Enable() }
// Draw draws the scene.
func (r SceneRef) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
r.scene.Draw(screen, opts)

View file

@ -22,13 +22,13 @@ func init() {
// Sprite combines an Actor with the ability to Draw from a single spritesheet.
type Sprite struct {
ID
Actor
ZOrder
FrameSize image.Point
FrameOffset image.Point
Hidden bool
ID
Hidden
Src ImageRef
ZOrder
anim *Anim
}

View file

@ -27,14 +27,14 @@ func init() {
// Tilemap renders a grid of tiles.
type Tilemap struct {
ID
Disabled bool
ZOrder
Disabled
Hidden
Map map[image.Point]Tile
Ersatz bool // "fake wall"
Offset image.Point // world coordinates
Src ImageRef
TileSize int
ZOrder
}
// CollidesWith implements Collider.