summaryrefslogtreecommitdiff
path: root/extractor/gat_format.gd
blob: 712657b6d28329f545e6d3eaf99a77e6952deca1 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class_name GATFormat


## Byte Length: 4 [br]
## GRAT
var signature: String = "GRAT"

## Byte Type: u8 [br]
## Byte Length: 2
var version: Version

## Byte Type: i32 [br]
## Byte Length: 4
var map_width: int

## Byte Type: i32 [br]
## Byte Length: 4
var map_height: int

## Byte Length: [member map_width] * [member map_height]
var tiles: Array[Tile]


static func from_bytes(bytes: ByteStream) -> GATFormat:
	var gat_format = GATFormat.new()
	
	bytes.advance(gat_format.signature.length())
	
	@warning_ignore("shadowed_variable")
	var version = Version.new()
	version.major = bytes.decode_u8()
	version.minor = bytes.decode_u8()
	gat_format.version = version
	
	gat_format.map_width = bytes.decode_s32()
	gat_format.map_height = bytes.decode_s32()
	
	gat_format.tiles = [] as Array[Tile]
	for _n in gat_format.map_width * gat_format.map_height:
		gat_format.tiles.append(Tile.from_bytes(bytes))
	
	return gat_format


class Tile:
	## Byte Type: f32 [br]
	## Byte Length: 4 [br]
	## Orignal Coordinates: (0, 0)
	var bottom_left_altitude: int
	
	## Byte Type: f32 [br]
	## Byte Length: 4 [br]
	## Orignal Coordinates: (1, 0)
	var bottom_right_altitude: int
	
	## Byte Type: f32 [br]
	## Byte Length: 4 [br]
	## Orignal Coordinates: (0, 1)
	var top_left_altitude: int
	
	## Byte Type: f32 [br]
	## Byte Length: 4 [br]
	## Orignal Coordinates: (1, 1)
	var top_right_altitude: int
	
	## Byte Type: u32 ?[br]
	## Byte Length: 4 ?
	var terrain_type: int
	
	
	func get_height_map() -> Dictionary: # Dictionary[Vector2, int]
		return {
			Vector2(0, 0): top_left_altitude,
			Vector2(1, 0): top_right_altitude,
			Vector2(0, 1): bottom_left_altitude,
			Vector2(1, 1): bottom_right_altitude,
		}
	
	
	static func from_bytes(bytes: ByteStream) -> Tile:
		var tile = Tile.new()
		
		tile.bottom_left_altitude = bytes.decode_float()
		tile.bottom_right_altitude = bytes.decode_float()
		tile.top_left_altitude = bytes.decode_float()
		tile.top_right_altitude = bytes.decode_float()
		tile.terrain_type = bytes.decode_u32()
		
		return tile