2019-10-31 15:45:52 +03:00

220 lines
4.3 KiB
Go

package gamemap
import (
"github.com/gammazero/deque"
"lab.zaar.be/thefish/alchemyst-go/util"
)
import blt "lab.zaar.be/thefish/bearlibterminal"
type ColorHolder interface {
GetColor() uint32
}
type cdeque struct {
deque.Deque
}
func (c *cdeque) Next() uint8 {
c.Rotate(1)
return c.Front().(uint8)
}
type DanceColorHolder struct {
A uint8
R *cdeque
G *cdeque
B *cdeque
}
func (chd *DanceColorHolder) GetColor() uint32 {
return blt.ColorFromARGB(
chd.A,
chd.R.Next(),
chd.G.Next(),
chd.B.Next(),
)
}
type PlainColorHolder struct {
A uint8
R uint8
G uint8
B uint8
}
func (chb *PlainColorHolder) GetColor() uint32 {
return blt.ColorFromARGB(
chb.A,
chb.R,
chb.G,
chb.B,
)
}
type TileColorSet struct {
Fg ColorHolder
Bg ColorHolder
DarkFg ColorHolder
DarkBg ColorHolder
}
type Appearance struct {
Char string `json:"char"`
ColorSet *TileColorSet `json:"colorSet"`
}
var crng = util.NewRNG()
type Tile struct {
*Appearance `json:"app"`
Name string `json:"name"`
Description string `json:"desc"`
BlocksPass bool `json:"blocksPass"`
BlocksSight bool `json:"blocksSight"`
Colordance bool `json:"colordance"`
Explored bool
MustDraw bool
Visible bool
}
func (t *Tile) GetChar() string {
return t.Char
}
func (t *Tile) GetRawColor() uint32 {
if t.Visible {
return t.Appearance.ColorSet.Fg.GetColor()
} else {
return t.Appearance.ColorSet.DarkFg.GetColor()
}
}
func (t *Tile) GetRawBgColor() uint32 {
if t.Visible {
return t.Appearance.ColorSet.Bg.GetColor()
} else {
return t.Appearance.ColorSet.DarkBg.GetColor()
}
}
func singleColorRing(colorValue uint8) *cdeque {
c := &cdeque{}
c.PushBack(colorValue)
return c
}
func fillColorRing(colorValue uint8, minGlow, maxGlow, step int) *cdeque {
q := make([]uint8, 0)
color := int(colorValue)
for color < maxGlow {
q = append(q, uint8(color))
color = crng.Range(1, step) + color
}
color = crng.Range(0, step+minGlow)
q = append(q, uint8(color))
//for uint8(color) < uint8(colorValue) {
// q = append(q, uint8(color))
// color = crng.Range(1, step+minGlow)
//}
c := &cdeque{}
for _, v := range q {
c.PushBack(uint8(v))
}
return c
}
func NewWall() *Tile {
return &Tile{
Name: "Wall",
Description: "A dull rock wall",
BlocksPass: true,
BlocksSight: true,
Explored: false,
MustDraw: false,
Appearance: &Appearance{
Char: "#",
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 130, 110, 150},
Bg: &PlainColorHolder{255, 172, 170, 173},
DarkFg: &PlainColorHolder{255, 20, 20, 68},
DarkBg: &PlainColorHolder{255, 7, 7, 30},
},
},
}
}
func NewFloor() *Tile {
return &Tile{
Name: "Floor",
Description: "Dusty rock floor",
BlocksPass: false,
BlocksSight: false,
Explored: false,
MustDraw: false,
Appearance: &Appearance{
Char: ".",
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 220, 220, 250},
Bg: &PlainColorHolder{255, 19, 19, 70},
DarkFg: &PlainColorHolder{255, 30, 20, 50},
DarkBg: &PlainColorHolder{255, 7, 7, 30},
},
},
}
}
func NewWaterTile() *Tile {
//ch := &ColorHolder{19, 19, 70}
return &Tile{
Name: "Water",
Description: "Murky water",
BlocksPass: false,
BlocksSight: false,
Explored: false,
MustDraw: true, //fixme debug
Colordance: true,
Appearance: &Appearance{
Char: " ",
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 220, 220, 250},
Bg: &DanceColorHolder{
255,
singleColorRing(19),
fillColorRing(19, 0, 15, 2),
fillColorRing(70, 120, 220, 12),
},
DarkFg: &PlainColorHolder{255, 30, 20, 50 },
DarkBg: &PlainColorHolder{255, 7, 7, 30},
},
},
}
}
func NewDeepWaterTile() *Tile {
//ch := &ColorHolder{5, 2, 154}
return &Tile{
Name: "Deep Water",
Description: "Deep water",
BlocksPass: false,
BlocksSight: false,
Explored: false,
MustDraw: true, //fixme debug
Colordance: true,
Appearance: &Appearance{
Char: " ",
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 220, 220, 250},
Bg: &DanceColorHolder{
255,
singleColorRing(5),
fillColorRing(2,2,42,4),
fillColorRing(154, 150, 229, 12),
},
DarkFg: &PlainColorHolder{255, 30, 20, 50},
DarkBg: &PlainColorHolder{255, 7, 7, 30},
},
},
}
}