瀏覽代碼

v1.0.0-dev/server): Tile Type removed from json

Tile Type isn't needed in json, instead we can use pluralization for color and symbol.

If symbols and colors it's an animated tile, if it's symbol and color then it's a basic tile.
Steve Thielemann 1 年之前
父節點
當前提交
b5a89245b6

+ 20 - 0
Server/catalog.go

@@ -3,6 +3,8 @@ package main
 import (
 	"encoding/json"
 	"os"
+	"path/filepath"
+	"strings"
 )
 
 type Catalog struct {
@@ -29,6 +31,24 @@ func (c *Catalog) LoadFile(filename string) error {
 	return nil
 }
 
+func (c *Catalog) LoadTiles(dirname string) error {
+	ls, err := os.ReadDir(dirname)
+	if err != nil {
+		return err
+	}
+	for _, ent := range ls {
+		// Ignore: hidden, dirs, non json, template
+		if strings.HasPrefix(ent.Name(), ".") || ent.IsDir() || !strings.HasSuffix(ent.Name(), ".json") || ent.Name() == "0_template.json" {
+			continue
+		}
+		err = c.LoadFile(filepath.Join(dirname, ent.Name()))
+		if err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
 func (c *Catalog) FindByName(name string) (int, bool) {
 	for idx, t := range c.Tiles {
 		if t.Name() == name {

+ 12 - 17
Server/main.go

@@ -22,30 +22,25 @@ func main() {
 			return
 		}
 	}
-	err = c.LoadFile(filepath.Join("content", "tiles", "0_template.json"))
+	err = c.LoadTiles(filepath.Join("content", "tiles"))
 	if err != nil {
-		_, err = os.Stat(filepath.Join("content", "tiles"))
-		if err != nil {
-			os.MkdirAll(filepath.Join("content", "tiles"), 0775)
-		}
-		err = c.MakeTemplate(filepath.Join("content", "tiles", "0_template.json"))
-		if err != nil {
-			log.Printf("MakeTemplate: %v", err)
-			return
-		}
-		err = c.LoadFile(filepath.Join("content", "tiles", "0_template.json"))
-		if err != nil {
-			log.Printf("LoadFile: %v", err)
-			return
-		}
+		log.Printf("LoadTiles: %v", err)
+		return
 	}
 	fmt.Printf("Tiles: %d\n", len(c.Tiles))
 	for idx, t := range c.Tiles {
 		switch t.Type() {
 		case BasicTile:
-			fmt.Printf("  %3d %s\n", idx, t.Name())
+			fmt.Printf("  %3d %-30s (1) %s\n", idx, t.Name(), t.Symbol())
 		case AnimatedTile:
-			fmt.Printf("A %3d %s\n", idx, t.Name())
+			symbols := ""
+			for range make([]byte, t.Len()) {
+				if symbols == "" || symbols != t.Symbol() {
+					symbols += t.Symbol()
+				}
+				t.Next()
+			}
+			fmt.Printf("A %3d %-30s (%d) %s\n", idx, t.Name(), t.Len(), symbols)
 		}
 	}
 }

+ 1 - 0
Server/tile.go

@@ -17,6 +17,7 @@ type Tile interface {
 	Color() string
 
 	Next()
+	Len() int
 
 	ToMap() map[string]any
 }

+ 4 - 0
Server/tile_animated.go

@@ -30,6 +30,10 @@ func (t *TileAnimated) Next() {
 	}
 }
 
+func (t *TileAnimated) Len() int {
+	return len(t.symbols)
+}
+
 func (t *TileAnimated) ToMap() map[string]any {
 	return map[string]any{
 		"name":    t.name,

+ 4 - 0
Server/tile_basic.go

@@ -24,6 +24,10 @@ func (t *TileBasic) Color() string {
 
 func (t *TileBasic) Next() {}
 
+func (t *TileBasic) Len() int {
+	return 1
+}
+
 func (t *TileBasic) ToMap() map[string]any {
 	return map[string]any{
 		"name":   t.name,

+ 322 - 0
content/tiles/0_base.json

@@ -0,0 +1,322 @@
+[
+  {
+    "color": "WHI ON BLA",
+    "name": "void",
+    "symbol": " "
+  },
+  {
+    "colors": [
+      "BRI RED ON BLA",
+      "RED ON BLA",
+      "WHI ON BLA",
+      "GRE ON BLA",
+      "BRI GRE ON BLA",
+      "GRE ON BLA",
+      "WHI ON BLA"
+    ],
+    "name": "red-green",
+    "symbols": [
+      "Red Green",
+      "Red Green",
+      "Red Green",
+      "Red Green",
+      "Red Green",
+      "Red Green",
+      "Red Green"
+    ]
+  },
+  {
+    "colors": [
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA"
+    ],
+    "name": "wheel-blue",
+    "symbols": [
+      "/",
+      "-",
+      "\\",
+      "|"
+    ]
+  },
+  {
+    "colors": [
+      "BRI RED ON BLA",
+      "BRI RED ON BLA",
+      "BRI RED ON BLA",
+      "BRI RED ON BLA"
+    ],
+    "name": "wheel-red",
+    "symbols": [
+      "/",
+      "-",
+      "\\",
+      "|"
+    ]
+  },
+  {
+    "colors": [
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA"
+    ],
+    "name": "wheel-green",
+    "symbols": [
+      "/",
+      "-",
+      "\\",
+      "|"
+    ]
+  },
+  {
+    "colors": [
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA"
+    ],
+    "name": "wheel-yellow",
+    "symbols": [
+      "/",
+      "-",
+      "\\",
+      "|"
+    ]
+  },
+  {
+    "colors": [
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA"
+    ],
+    "name": "wheel-magenta",
+    "symbols": [
+      "/",
+      "-",
+      "\\",
+      "|"
+    ]
+  },
+  {
+    "colors": [
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA"
+    ],
+    "name": "wheel-white",
+    "symbols": [
+      "/",
+      "-",
+      "\\",
+      "|"
+    ]
+  },
+  {
+    "colors": [
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA"
+    ],
+    "name": "split-blue",
+    "symbols": [
+      "-",
+      "<",
+      "|",
+      ">",
+      "-",
+      ">",
+      "|",
+      "<"
+    ]
+  },
+  {
+    "colors": [
+      "BRI RED ON BLA",
+      "BRI RED ON BLA",
+      "BRI RED ON BLA",
+      "BRI RED ON BLA",
+      "BRI RED ON BLA",
+      "BRI RED ON BLA",
+      "BRI RED ON BLA",
+      "BRI RED ON BLA"
+    ],
+    "name": "split-red",
+    "symbols": [
+      "-",
+      "<",
+      "|",
+      ">",
+      "-",
+      ">",
+      "|",
+      "<"
+    ]
+  },
+  {
+    "colors": [
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA"
+    ],
+    "name": "split-green",
+    "symbols": [
+      "-",
+      "<",
+      "|",
+      ">",
+      "-",
+      ">",
+      "|",
+      "<"
+    ]
+  },
+  {
+    "colors": [
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA"
+    ],
+    "name": "split-yellow",
+    "symbols": [
+      "-",
+      "<",
+      "|",
+      ">",
+      "-",
+      ">",
+      "|",
+      "<"
+    ]
+  },
+  {
+    "colors": [
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA"
+    ],
+    "name": "split-magenta",
+    "symbols": [
+      "-",
+      "<",
+      "|",
+      ">",
+      "-",
+      ">",
+      "|",
+      "<"
+    ]
+  },
+  {
+    "colors": [
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA"
+    ],
+    "name": "split-white",
+    "symbols": [
+      "-",
+      "<",
+      "|",
+      ">",
+      "-",
+      ">",
+      "|",
+      "<"
+    ]
+  },
+  {
+    "colors": [
+      "BRI CYA ON BLA",
+      "BRI CYA ON BLA"
+    ],
+    "name": "x-blue",
+    "symbols": [
+      "X",
+      "+"
+    ]
+  },
+  {
+    "colors": [
+      "BRI RED ON BLA",
+      "BRI RED ON BLA"
+    ],
+    "name": "x-red",
+    "symbols": [
+      "X",
+      "+"
+    ]
+  },
+  {
+    "colors": [
+      "BRI GRE ON BLA",
+      "BRI GRE ON BLA"
+    ],
+    "name": "x-green",
+    "symbols": [
+      "X",
+      "+"
+    ]
+  },
+  {
+    "colors": [
+      "BRI YEL ON BLA",
+      "BRI YEL ON BLA"
+    ],
+    "name": "x-yellow",
+    "symbols": [
+      "X",
+      "+"
+    ]
+  },
+  {
+    "colors": [
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA"
+    ],
+    "name": "x-magenta",
+    "symbols": [
+      "X",
+      "+"
+    ]
+  },
+  {
+    "colors": [
+      "BRI WHI ON BLA",
+      "BRI WHI ON BLA"
+    ],
+    "name": "x-white",
+    "symbols": [
+      "X",
+      "+"
+    ]
+  }
+]

+ 37 - 0
content/tiles/1_players.json

@@ -0,0 +1,37 @@
+[
+  {
+    "color": "BRI GRE ON BLA",
+    "name": "player-curent",
+    "symbol": "@"
+  },
+  {
+    "color": "BRI BLA ON BLA",
+    "name": "player-offline",
+    "symbol": "@"
+  },
+  {
+    "color": "WHI ON BLA",
+    "name": "player-neutral",
+    "symbol": "@"
+  },
+  {
+    "color": "GRE ON BLA",
+    "name": "player-ally",
+    "symbol": "@"
+  },
+  {
+    "color": "BRI RED ON BLA",
+    "name": "player-hostile",
+    "symbol": "@"
+  },
+  {
+    "color": "BRI MAG ON BLA",
+    "name": "player-party",
+    "symbol": "@"
+  },
+  {
+    "color": "BRI YEL ON BLA",
+    "name": "player-party-leader",
+    "symbol": "@"
+  }
+]

+ 64 - 0
content/tiles/2_terrain.json

@@ -0,0 +1,64 @@
+[
+  {
+    "color": "BRI GRE ON BLA",
+    "name": "grass-summer",
+    "symbol": "."
+  },
+  {
+    "color": "BRI GRE ON BLA",
+    "name": "grass-spring",
+    "symbol": "."
+  },
+  {
+    "color": "GRE ON BLA",
+    "name": "grass-autumn",
+    "symbol": "."
+  },
+  {
+    "color": "BRI WHI ON BLA",
+    "name": "grass-winter",
+    "symbol": "."
+  },
+  {
+    "color": "BRI YEL ON BLA",
+    "name": "sand",
+    "symbol": "."
+  },
+  {
+    "color": "WHI ON BLA",
+    "name": "stone",
+    "symbol": "."
+  },
+  {
+    "color": "WHI ON BLA",
+    "name": "mountain-stoney",
+    "symbol": "^"
+  },
+  {
+    "color": "BRI WHI ON BLA",
+    "name": "mountain-snowy",
+    "symbol": "^"
+  },
+  {
+    "colors": [
+      "BRI CYA ON BLU",
+      "CYA ON BLU"
+    ],
+    "name": "water-shallow",
+    "symbols": [
+      "~",
+      "~"
+    ]
+  },
+  {
+    "colors": [
+      "BRI BLU ON BLU",
+      "BLA ON BLU"
+    ],
+    "name": "water-deep",
+    "symbols": [
+      "~",
+      "~"
+    ]
+  }
+]

+ 97 - 0
content/tiles/3_towns.json

@@ -0,0 +1,97 @@
+[
+  {
+    "color": "BRI GRE ON BLA",
+    "name": "village-own",
+    "symbol": "V"
+  },
+  {
+    "color": "GRE ON BLA",
+    "name": "village-member",
+    "symbol": "V"
+  },
+  {
+    "color": "GRE ON BLA",
+    "name": "village-ally",
+    "symbol": "V"
+  },
+  {
+    "color": "BRO ON BLA",
+    "name": "village-neutral",
+    "symbol": "V"
+  },
+  {
+    "color": "RED ON BLA",
+    "name": "village-hostile",
+    "symbol": "V"
+  },
+  {
+    "color": "MAG ON BLA",
+    "name": "village-party",
+    "symbol": "V"
+  },
+  {
+    "color": "BRI GRE ON BLA",
+    "name": "town-own",
+    "symbol": "T"
+  },
+  {
+    "color": "GRE ON BLA",
+    "name": "town-member",
+    "symbol": "T"
+  },
+  {
+    "color": "GRE ON BLA",
+    "name": "town-ally",
+    "symbol": "T"
+  },
+  {
+    "color": "BRO ON BLA",
+    "name": "town-neutral",
+    "symbol": "T"
+  },
+  {
+    "color": "RED ON BLA",
+    "name": "town-hostile",
+    "symbol": "T"
+  },
+  {
+    "color": "MAG ON BLA",
+    "name": "town-party",
+    "symbol": "T"
+  },
+  {
+    "color": "BRI GRE ON BLA",
+    "name": "city-own",
+    "symbol": "C"
+  },
+  {
+    "color": "GRE ON BLA",
+    "name": "city-member",
+    "symbol": "C"
+  },
+  {
+    "color": "GRE ON BLA",
+    "name": "city-ally",
+    "symbol": "C"
+  },
+  {
+    "color": "BRO ON BLA",
+    "name": "city-neutral",
+    "symbol": "C"
+  },
+  {
+    "color": "RED ON BLA",
+    "name": "city-hostile",
+    "symbol": "C"
+  },
+  {
+    "color": "MAG ON BLA",
+    "name": "city-party",
+    "symbol": "C"
+  },
+  {
+    "color": "MAG ON BLA",
+    "name": "dungeon",
+    "symbol": "D"
+  }
+]

+ 68 - 0
content/tiles/4_interior.json

@@ -0,0 +1,68 @@
+[
+  {
+    "color": "BRO ON BLA",
+    "name": "wall-wood",
+    "symbol": "#"
+  },
+  {
+    "color": "WHI ON BLA",
+    "name": "wall-stone",
+    "symbol": "#"
+  },
+  {
+    "color": "BRI WHI ON BLA",
+    "name": "wall-iron",
+    "symbol": "#"
+  },
+  {
+    "colors": [
+      "BRI MAG ON BLA",
+      "MAG ON BLA"
+    ],
+    "name": "wall-magic",
+    "symbols": [
+      "#",
+      "#"
+    ]
+  },
+  {
+    "color": "BRO ON BLA",
+    "name": "floor-wood",
+    "symbol": "_"
+  },
+  {
+    "color": "WHI ON BLA",
+    "name": "floor-stone",
+    "symbol": "_"
+  },
+  {
+    "color": "BRI WHI ON BLA",
+    "name": "floor-iron",
+    "symbol": "_"
+  },
+  {
+    "color": "BRO ON BLA",
+    "name": "door-wood",
+    "symbol": "+"
+  },
+  {
+    "color": "WHI ON BLA",
+    "name": "door-stone",
+    "symbol": "+"
+  },
+  {
+    "color": "BRI WHI ON BLA",
+    "name": "door-iron",
+    "symbol": "+"
+  },
+  {
+    "color": "MAG ON BLA",
+    "name": "door-dungeon",
+    "symbol": "+"
+  },
+  {
+    "color": "BRI YEL ON BLA",
+    "name": "door-locked",
+    "symbol": "+"
+  }
+]

+ 78 - 0
content/tiles/5_constructs.json

@@ -0,0 +1,78 @@
+[
+  {
+    "color": "BRO ON BLA",
+    "name": "chest-private",
+    "symbol": "c"
+  },
+  {
+    "color": "BRI GRE ON BLA",
+    "name": "chest-public",
+    "symbol": "c"
+  },
+  {
+    "color": "BRI YEL ON BLA",
+    "name": "chest-shop",
+    "symbol": "c"
+  },
+  {
+    "color": "GRE ON BLA",
+    "name": "chest-town",
+    "symbol": "c"
+  },
+  {
+    "color": "MAG ON BLA",
+    "name": "chest-ender",
+    "symbol": "c"
+  },
+  {
+    "color": "BRO ON BLA",
+    "name": "chest-dungeon",
+    "symbol": "c"
+  },
+  {
+    "color": "BRI YEL ON BLA",
+    "name": "bank",
+    "symbol": "B"
+  },
+  {
+    "color": "BRI WHI ON BLA",
+    "name": "eagle-nest-public",
+    "symbol": "u"
+  },
+  {
+    "color": "BRI BLA ON BLA",
+    "name": "eagle-nest-empty",
+    "symbol": "u"
+  },
+  {
+    "color": "WHI ON BLA",
+    "name": "eagle-nest-private",
+    "symbol": "u"
+  },
+  {
+    "color": "BRI YEL ON BLA",
+    "name": "eagle-nest-toll",
+    "symbol": "u"
+  },
+  {
+    "color": "MAG ON BLA",
+    "name": "eagle-nest-member",
+    "symbol": "u"
+  },
+  {
+    "color": "BRI MAG ON BLA",
+    "name": "mail-box",
+    "symbol": "%"
+  },
+  {
+    "colors": [
+      "BRI MAG ON BLA",
+      "BRI MAG ON BLA"
+    ],
+    "name": "mail-box-new",
+    "symbols": [
+      "%",
+      "/"
+    ]
+  }
+]