mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-25 19:46:50 -05:00
add comments to d2ds1/layer.go
This commit is contained in:
parent
198a28505e
commit
87c121707d
@ -24,10 +24,12 @@ type (
|
||||
tileGrid []tileRow // index is y coordinate
|
||||
)
|
||||
|
||||
// Layer is an abstraction of a tile grid with some helper methods
|
||||
type Layer struct {
|
||||
tiles tileGrid
|
||||
}
|
||||
|
||||
// Tile returns the tile at the given x,y coordinate in the grid, or nil if empty.
|
||||
func (l *Layer) Tile(x, y int) *Tile {
|
||||
if l.Width() < x || l.Height() < y {
|
||||
return nil
|
||||
@ -36,6 +38,7 @@ func (l *Layer) Tile(x, y int) *Tile {
|
||||
return &l.tiles[y][x]
|
||||
}
|
||||
|
||||
// SetTile sets the tile at the given x,y coordinate in the tile grid
|
||||
func (l *Layer) SetTile(x, y int, t *Tile) {
|
||||
if l.Width() > x || l.Height() > y {
|
||||
return
|
||||
@ -44,6 +47,7 @@ func (l *Layer) SetTile(x, y int, t *Tile) {
|
||||
l.tiles[y][x] = *t
|
||||
}
|
||||
|
||||
// Width returns the width of the tile grid
|
||||
func (l *Layer) Width() int {
|
||||
if len(l.tiles[0]) < 1 {
|
||||
l.SetWidth(1)
|
||||
@ -52,6 +56,7 @@ func (l *Layer) Width() int {
|
||||
return len(l.tiles[0])
|
||||
}
|
||||
|
||||
// SetWidth sets the width of the tile grid, minimum of 1
|
||||
func (l *Layer) SetWidth(w int) *Layer {
|
||||
if w < 1 {
|
||||
w = 1
|
||||
@ -82,6 +87,7 @@ func (l *Layer) SetWidth(w int) *Layer {
|
||||
return l
|
||||
}
|
||||
|
||||
// Height returns the height of the tile grid
|
||||
func (l *Layer) Height() int {
|
||||
if len(l.tiles) < 1 {
|
||||
l.SetHeight(1)
|
||||
@ -90,6 +96,7 @@ func (l *Layer) Height() int {
|
||||
return len(l.tiles)
|
||||
}
|
||||
|
||||
// SetHeight sets the height of the tile grid, minimum of 1
|
||||
func (l *Layer) SetHeight(h int) *Layer {
|
||||
if h < 1 {
|
||||
h = 1
|
||||
@ -122,10 +129,12 @@ func (l *Layer) SetHeight(h int) *Layer {
|
||||
return l
|
||||
}
|
||||
|
||||
// Size returns the width and height of the tile grid
|
||||
func (l *Layer) Size() (w, h int) {
|
||||
return l.Width(), l.Height()
|
||||
}
|
||||
|
||||
// SetSize sets the width and height of the tile grid
|
||||
func (l *Layer) SetSize(w, h int) *Layer {
|
||||
return l.SetWidth(w).SetHeight(h)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user