summaryrefslogtreecommitdiff
path: root/engine/Components/World/Descriptor.go
blob: 553aa5b7a9d8b34a5d1c17cf9022600d13f5f3d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package world

import rl "github.com/gen2brain/raylib-go/raylib"

type Descriptor struct {
	TileSize rl.Vector2
	Textures map[int]string `json:"textures"`
	WorldMap [][]TileDescriptor `json:"worldmap"`
}

func (base *Descriptor) GenerateMap() *World {
	var outp = &World {
		TileSize: base.TileSize,
		TextureNames: base.Textures,
		Tiles: make([][]Tile, len(base.WorldMap)),
	}
	for x := range base.WorldMap {
		outp.Tiles[x] = make([]Tile, len(base.WorldMap[x]))
		for y, tile := range base.WorldMap[x] {
			outp.Tiles[x][y] = &StandardTile {
				X: float32(x),
				Y: float32(y),
				ParentWorld: outp,
				Descriptor: tile,
			}
		}
	}
	return outp
}