started tile serializing
This commit is contained in:
@ -1,3 +0,0 @@
|
||||
- load prefabs
|
||||
- compose from gens and prefabs
|
||||
- editor for prefabs
|
@ -10,7 +10,6 @@ type Tile struct {
|
||||
Description string `json:"desc"`
|
||||
BlocksPass bool `json:"blocksPass"`
|
||||
BlocksSight bool `json:"blocksSight"`
|
||||
Colordance bool `json:"colordance"`
|
||||
Explored bool
|
||||
MustDraw bool
|
||||
Visible bool
|
||||
@ -46,7 +45,7 @@ func NewWall() *Tile {
|
||||
MustDraw: false,
|
||||
Appearance: &Appearance{
|
||||
Glyph: &PlainGlyphHolder{"#"},
|
||||
ColorSet: &TileColorSet{
|
||||
ColorSet: TileColorSet{
|
||||
Fg: &PlainColorHolder{255, 130, 110, 150},
|
||||
Bg: &PlainColorHolder{255, 172, 170, 173},
|
||||
DarkFg: &PlainColorHolder{255, 20, 20, 68},
|
||||
@ -66,7 +65,7 @@ func NewFloor() *Tile {
|
||||
MustDraw: false,
|
||||
Appearance: &Appearance{
|
||||
Glyph: &PlainGlyphHolder{"."},
|
||||
ColorSet: &TileColorSet{
|
||||
ColorSet: TileColorSet{
|
||||
Fg: &PlainColorHolder{255, 220, 220, 250},
|
||||
Bg: &PlainColorHolder{255, 19, 19, 70},
|
||||
DarkFg: &PlainColorHolder{255, 30, 20, 50},
|
||||
@ -85,11 +84,10 @@ func NewWaterTile() *Tile {
|
||||
BlocksSight: false,
|
||||
Explored: false,
|
||||
MustDraw: true, //fixme debug
|
||||
Colordance: true,
|
||||
|
||||
Appearance: &Appearance{
|
||||
Glyph: &PlainGlyphHolder{" "},
|
||||
ColorSet: &TileColorSet{
|
||||
ColorSet: TileColorSet{
|
||||
Fg: &PlainColorHolder{255, 220, 220, 250},
|
||||
Bg: &DanceColorHolder{
|
||||
255,
|
||||
@ -113,10 +111,9 @@ func NewDeepWaterTile() *Tile {
|
||||
BlocksSight: false,
|
||||
Explored: false,
|
||||
MustDraw: true, //fixme debug
|
||||
Colordance: true,
|
||||
Appearance: &Appearance{
|
||||
Glyph: &PlainGlyphHolder{" "},
|
||||
ColorSet: &TileColorSet{
|
||||
ColorSet: TileColorSet{
|
||||
Fg: &PlainColorHolder{255, 220, 220, 250},
|
||||
Bg: &DanceColorHolder{
|
||||
255,
|
||||
|
9
engine/items/carried.go
Normal file
9
engine/items/carried.go
Normal file
@ -0,0 +1,9 @@
|
||||
package items
|
||||
|
||||
import "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
|
||||
|
||||
type Carried struct {}
|
||||
|
||||
func (c *Carried) Type() string {
|
||||
return ecs.CarriedComponent
|
||||
}
|
10
engine/items/useable.go
Normal file
10
engine/items/useable.go
Normal file
@ -0,0 +1,10 @@
|
||||
package items
|
||||
|
||||
import "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
|
||||
|
||||
type Useable struct {}
|
||||
|
||||
|
||||
func (u *Useable) Type() string {
|
||||
return ecs.UsableComponent
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gammazero/deque"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util"
|
||||
@ -29,12 +31,12 @@ type DanceColorHolder struct {
|
||||
B *cdeque
|
||||
}
|
||||
|
||||
func (chd *DanceColorHolder) GetColor() uint32 {
|
||||
func (dch DanceColorHolder) GetColor() uint32 {
|
||||
return blt.ColorFromARGB(
|
||||
chd.A,
|
||||
chd.R.Next(),
|
||||
chd.G.Next(),
|
||||
chd.B.Next(),
|
||||
dch.A,
|
||||
dch.R.Next(),
|
||||
dch.G.Next(),
|
||||
dch.B.Next(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -45,7 +47,7 @@ type PlainColorHolder struct {
|
||||
B uint8
|
||||
}
|
||||
|
||||
func (chb *PlainColorHolder) GetColor() uint32 {
|
||||
func (chb PlainColorHolder) GetColor() uint32 {
|
||||
return blt.ColorFromARGB(
|
||||
chb.A,
|
||||
chb.R,
|
||||
@ -55,10 +57,10 @@ func (chb *PlainColorHolder) GetColor() uint32 {
|
||||
}
|
||||
|
||||
type TileColorSet struct {
|
||||
Fg ColorHolder
|
||||
Bg ColorHolder
|
||||
DarkFg ColorHolder
|
||||
DarkBg ColorHolder
|
||||
Fg ColorHolder `json:"fg"`
|
||||
Bg ColorHolder `json:"bg"`
|
||||
DarkFg ColorHolder `json:"darkfg"`
|
||||
DarkBg ColorHolder `json:"darkbg"`
|
||||
}
|
||||
|
||||
|
||||
@ -70,13 +72,13 @@ type PlainGlyphHolder struct {
|
||||
Glyph string
|
||||
}
|
||||
|
||||
func (pch *PlainGlyphHolder) GetGlyph() string {
|
||||
return pch.Glyph
|
||||
func (pgh PlainGlyphHolder) GetGlyph() string {
|
||||
return pgh.Glyph
|
||||
}
|
||||
|
||||
type Appearance struct {
|
||||
Glyph GlyphHolder `json:"char"`
|
||||
ColorSet *TileColorSet `json:"colorSet"`
|
||||
Glyph GlyphHolder `json:"glyph"`
|
||||
ColorSet TileColorSet `json:"colorSet"`
|
||||
}
|
||||
|
||||
func SingleColorRing(colorValue uint8) *cdeque {
|
||||
@ -108,4 +110,51 @@ func FillColorRing(colorValue uint8, minGlow, maxGlow, step int) *cdeque {
|
||||
|
||||
func (app Appearance) Type() string {
|
||||
return ecs.AppearanceComponent
|
||||
}
|
||||
|
||||
func (app *Appearance) MarshalJSON() ([]byte, error) {
|
||||
buffer := bytes.NewBufferString("{")
|
||||
//glyph
|
||||
buffer.WriteString(`"glyph":{`)
|
||||
switch app.Glyph.(type) {
|
||||
case PlainGlyphHolder:
|
||||
buffer.WriteString(fmt.Sprintf(`"type":"plain", "chars":"%s"`, app.Glyph.GetGlyph()))
|
||||
break
|
||||
}
|
||||
//note the comma
|
||||
buffer.WriteString("},")
|
||||
|
||||
//color
|
||||
buffer.WriteString(`"color":{`)
|
||||
buffer.WriteString(getColorJson("fg", app.ColorSet.Fg) + ",")
|
||||
buffer.WriteString(getColorJson("bg", app.ColorSet.Fg) + ",")
|
||||
buffer.WriteString(getColorJson("darkfg", app.ColorSet.Fg) + ",")
|
||||
buffer.WriteString(getColorJson("darkbg", app.ColorSet.Fg))
|
||||
|
||||
buffer.WriteString("}")
|
||||
|
||||
buffer.WriteString("}")
|
||||
return buffer.Bytes(), nil
|
||||
}
|
||||
|
||||
func (app *Appearance) UnmarshalJSON(buffer []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getColorJson(field string, holder ColorHolder) string {
|
||||
result := ""
|
||||
switch holder.(type) {
|
||||
case PlainColorHolder:
|
||||
result = fmt.Sprintf(`"plain":[%d,%d,%d,%d]`,
|
||||
holder.(PlainColorHolder).A,
|
||||
holder.(PlainColorHolder).R,
|
||||
holder.(PlainColorHolder).G,
|
||||
holder.(PlainColorHolder).B,
|
||||
)
|
||||
break
|
||||
case DanceColorHolder:
|
||||
return "" //fixme!!!
|
||||
break
|
||||
}
|
||||
return fmt.Sprintf(`"%s":%s`, field, result)
|
||||
}
|
Reference in New Issue
Block a user