package gamemap

import (
	. "lab.zaar.be/thefish/alchemyst-go/engine/types"
)

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.Glyph.GetGlyph()
}

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 NewWall() *Tile {
	return &Tile{
		Name:        "Wall",
		Description: "A dull rock wall",
		BlocksPass:  true,
		BlocksSight: true,
		Explored:    false,
		MustDraw:    false,
		Appearance: &Appearance{
			Glyph: &PlainGlyphHolder{"#"},
			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{
			Glyph: &PlainGlyphHolder{"."},
			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{
			Glyph: &PlainGlyphHolder{" "},
			ColorSet: &TileColorSet{
				Fg: &PlainColorHolder{255, 220, 220, 250},
				Bg: &DanceColorHolder{
					255,
					SingleColorRing(19),
					FillColorRing(19, 0, 15, 2),
					FillColorRing(127, 120, 176, 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{
			Glyph: &PlainGlyphHolder{" "},
			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},
			},
		},
	}
}