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"`
	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{
		Appearance:  &Appearance{
            Glyph: &PlainGlyphHolder{Glyph: "#"},
            ColorSet: TileColorSet{
                Fg: &PlainColorHolder{A: 255, R: 130, G: 110, B: 150},
                Bg: &PlainColorHolder{A: 255, R: 172, G: 170, B: 173},
                DarkFg: &PlainColorHolder{A: 255, R: 20, G: 20, B: 68},
                DarkBg: &PlainColorHolder{A: 255, R: 7, G: 7, B: 30},
            },
        },
		Name:        "Wall",
		Description: "A dull rock wall",
		BlocksPass:  true,
		BlocksSight: true,
		Explored:    false,
		MustDraw:    false,
		Visible:     false,
	}
}

func NewDecoratedWall() *Tile {
	return &Tile{
		Name:        "Decorated Wall",
		Description: "A rock wall covered with paintings",
		BlocksPass:  true,
		BlocksSight: true,
		Explored:    false,
		MustDraw:    false,
		Appearance: &Appearance{
			Glyph: &PlainGlyphHolder{Glyph: "#"},
			ColorSet: TileColorSet{
				Fg:     &PlainColorHolder{A: 255, R: 130, G: 110, B: 150},
				//Bg:     &PlainColorHolder{255, 172, 170, 173},
				Bg:     &DanceColorHolder{
					A: 255,
					R: DeviatedColorRing(172, -15, 10),
					G: DeviatedColorRing(170, -5, 15),
					B: DeviatedColorRing(173, -10, 10),
				},
				DarkFg: &PlainColorHolder{A: 255, R: 20, G: 20, B: 68},
				DarkBg: &PlainColorHolder{A: 255, R: 7, G: 7, B: 30},
			},
		},
	}
}

func NewFloor() *Tile {
	return &Tile{
		Name:        "Floor",
		Description: "Dusty rock floor",
		BlocksPass:  false,
		BlocksSight: false,
		Explored:    false,
		MustDraw:    false,
		Appearance: &Appearance{
			Glyph: &PlainGlyphHolder{Glyph: "."},
			ColorSet: TileColorSet{
				Fg:     &PlainColorHolder{A: 255, R: 220, G: 220, B: 250},
				Bg:     &PlainColorHolder{A: 255, R: 19, G: 19, B: 70},
				DarkFg: &PlainColorHolder{A: 255, R: 30, G: 20, B: 50},
				DarkBg: &PlainColorHolder{A: 255, R: 7, G: 7, B: 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
		Appearance: &Appearance{
			Glyph: &PlainGlyphHolder{Glyph: " "},
			ColorSet: TileColorSet{
				Fg: &PlainColorHolder{A: 255, R: 220, G: 220, B: 250},
				Bg: &DanceColorHolder{
					A: 255,
					R: SingleColorRing(5),
					G: FillColorRing(2, 2, 42, 4),
					B: FillColorRing(154, 150, 229, 12),
				},
				DarkFg: &PlainColorHolder{A: 255, R: 30, G: 20, B: 50},
				DarkBg: &PlainColorHolder{A: 255, R: 7, G: 7, B: 30},
			},
		},

	}
}

func NewDeepWaterTile() *Tile {
	//ch := &ColorHolder{5, 2, 154}
	return &Tile{
		Appearance:  &Appearance{
            Glyph: &PlainGlyphHolder{Glyph: " "},
            ColorSet: TileColorSet{
                Fg: &PlainColorHolder{A: 255, R: 220, G: 220, B: 250},
                Bg: &DanceColorHolder{A: 255, R: SingleColorRing(19), G: FillColorRing(19, 0, 15, 2), B: FillColorRing(127, 120, 176, 12)},
                DarkFg: &PlainColorHolder{A: 255, R: 30, G: 20, B: 50},
                DarkBg: &PlainColorHolder{A: 255, R: 7, G: 7, B: 30},
            },
        },
		Name:        "Deep Water",
		Description: "Deep water",
		BlocksPass:  false,
		BlocksSight: false,
		Explored:    false,
		MustDraw:    true,
		Visible:     false,
	}
}
