2024-04-27 22:32:05 +03:00
|
|
|
package model
|
|
|
|
|
2024-05-03 13:46:32 +03:00
|
|
|
import (
|
|
|
|
"mvvasilev/last_light/util"
|
|
|
|
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
)
|
2024-04-27 22:32:05 +03:00
|
|
|
|
|
|
|
type Material uint
|
|
|
|
|
|
|
|
const (
|
|
|
|
MaterialGround Material = iota
|
|
|
|
MaterialRock
|
2024-05-03 13:46:32 +03:00
|
|
|
MaterialWall
|
2024-04-27 22:32:05 +03:00
|
|
|
MaterialGrass
|
|
|
|
MaterialVoid
|
|
|
|
)
|
|
|
|
|
|
|
|
type TileType struct {
|
|
|
|
Material Material
|
|
|
|
Passable bool
|
|
|
|
Presentation rune
|
2024-05-03 13:46:32 +03:00
|
|
|
Transparent bool
|
|
|
|
Style tcell.Style
|
2024-04-27 22:32:05 +03:00
|
|
|
}
|
|
|
|
|
2024-05-03 13:46:32 +03:00
|
|
|
func TileTypeGround() TileType {
|
2024-04-27 22:32:05 +03:00
|
|
|
return TileType{
|
|
|
|
Material: MaterialGround,
|
|
|
|
Passable: true,
|
|
|
|
Presentation: '.',
|
2024-05-03 13:46:32 +03:00
|
|
|
Transparent: false,
|
|
|
|
Style: tcell.StyleDefault,
|
2024-04-27 22:32:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-03 13:46:32 +03:00
|
|
|
func TileTypeRock() TileType {
|
2024-04-27 22:32:05 +03:00
|
|
|
return TileType{
|
|
|
|
Material: MaterialRock,
|
|
|
|
Passable: false,
|
|
|
|
Presentation: '█',
|
2024-05-03 13:46:32 +03:00
|
|
|
Transparent: false,
|
|
|
|
Style: tcell.StyleDefault,
|
2024-04-27 22:32:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-03 13:46:32 +03:00
|
|
|
func TileTypeGrass() TileType {
|
2024-04-27 22:32:05 +03:00
|
|
|
return TileType{
|
|
|
|
Material: MaterialGrass,
|
|
|
|
Passable: true,
|
|
|
|
Presentation: ',',
|
2024-05-03 13:46:32 +03:00
|
|
|
Transparent: false,
|
|
|
|
Style: tcell.StyleDefault,
|
2024-04-27 22:32:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-03 13:46:32 +03:00
|
|
|
func TileTypeVoid() TileType {
|
2024-04-27 22:32:05 +03:00
|
|
|
return TileType{
|
|
|
|
Material: MaterialVoid,
|
|
|
|
Passable: false,
|
|
|
|
Presentation: ' ',
|
2024-05-03 13:46:32 +03:00
|
|
|
Transparent: true,
|
|
|
|
Style: tcell.StyleDefault,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TileTypeWall() TileType {
|
|
|
|
return TileType{
|
|
|
|
Material: MaterialWall,
|
|
|
|
Passable: false,
|
|
|
|
Presentation: '#',
|
|
|
|
Transparent: false,
|
|
|
|
Style: tcell.StyleDefault.Background(tcell.ColorGray),
|
2024-04-27 22:32:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Tile interface {
|
|
|
|
Position() util.Position
|
2024-05-03 13:46:32 +03:00
|
|
|
Presentation() (rune, tcell.Style)
|
2024-04-27 22:32:05 +03:00
|
|
|
Passable() bool
|
2024-05-03 13:46:32 +03:00
|
|
|
Transparent() bool
|
2024-04-27 22:32:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type StaticTile struct {
|
|
|
|
position util.Position
|
|
|
|
t TileType
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateStaticTile(x, y int, t TileType) Tile {
|
|
|
|
st := new(StaticTile)
|
|
|
|
|
|
|
|
st.position = util.PositionAt(x, y)
|
|
|
|
st.t = t
|
|
|
|
|
|
|
|
return st
|
|
|
|
}
|
|
|
|
|
|
|
|
func (st *StaticTile) Position() util.Position {
|
|
|
|
return st.position
|
|
|
|
}
|
|
|
|
|
2024-05-03 13:46:32 +03:00
|
|
|
func (st *StaticTile) Presentation() (rune, tcell.Style) {
|
|
|
|
return st.t.Presentation, st.t.Style
|
2024-04-27 22:32:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (st *StaticTile) Passable() bool {
|
|
|
|
return st.t.Passable
|
|
|
|
}
|
|
|
|
|
2024-05-03 13:46:32 +03:00
|
|
|
func (st *StaticTile) Transparent() bool {
|
|
|
|
return st.t.Transparent
|
|
|
|
}
|
|
|
|
|
2024-04-27 22:32:05 +03:00
|
|
|
func (st *StaticTile) Type() TileType {
|
|
|
|
return st.t
|
|
|
|
}
|
2024-05-03 13:46:32 +03:00
|
|
|
|
|
|
|
type ItemTile struct {
|
|
|
|
position util.Position
|
|
|
|
itemType *ItemType
|
|
|
|
quantity int
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateItemTile(position util.Position, itemType *ItemType, quantity int) *ItemTile {
|
|
|
|
it := new(ItemTile)
|
|
|
|
|
|
|
|
it.position = position
|
|
|
|
it.itemType = itemType
|
|
|
|
it.quantity = quantity
|
|
|
|
|
|
|
|
return it
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *ItemTile) Type() *ItemType {
|
|
|
|
return it.itemType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *ItemTile) Quantity() int {
|
|
|
|
return it.quantity
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *ItemTile) Position() util.Position {
|
|
|
|
return it.position
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *ItemTile) Presentation() (rune, tcell.Style) {
|
|
|
|
return it.itemType.tileIcon, it.itemType.style
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *ItemTile) Passable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *ItemTile) Transparent() bool {
|
|
|
|
return false
|
|
|
|
}
|