2021-06-28 21:51:09 +02:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
enum TileType {
|
|
|
|
None,
|
|
|
|
Sand,
|
2022-01-06 22:26:53 +01:00
|
|
|
Grass,
|
|
|
|
DeepGrass
|
2021-06-28 21:51:09 +02:00
|
|
|
}
|
|
|
|
|
2021-06-28 22:34:48 +02:00
|
|
|
var TileTypeFromString = { "None": TileType.None, "Sand": TileType.Sand, "Grass": TileType.Grass }
|
2021-06-28 21:51:09 +02:00
|
|
|
var HexPoints = null
|
|
|
|
var HexColors = []
|
|
|
|
|
|
|
|
export(Vector2) var hex_scale = Vector2(1, 1) setget set_hex_scale
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
|
|
|
print ("Initialized")
|
|
|
|
set_hex_scale(Vector2(Globals.hex_size,Globals.hex_size))
|
|
|
|
|
|
|
|
|
|
|
|
func set_hex_scale(scale):
|
|
|
|
hex_scale = scale
|
|
|
|
|
|
|
|
HexPoints = PoolVector2Array()
|
|
|
|
|
|
|
|
for i in range (7):
|
|
|
|
var angle = (60 * i) * PI / 180
|
|
|
|
HexPoints.append(Vector2(cos(angle), sin(angle)) * hex_scale.x / 2)
|
|
|
|
|
2021-07-11 16:09:04 +02:00
|
|
|
var NoneColors = create_color_array ("#885555")
|
|
|
|
var SandColors = create_color_array ("#ffa106")
|
|
|
|
var GrassColors = create_color_array ("#4b9635")
|
2022-01-06 22:26:53 +01:00
|
|
|
var DeepGrassColors = create_color_array ("#2b5d1d")
|
2021-07-11 16:09:04 +02:00
|
|
|
|
2021-06-28 21:51:09 +02:00
|
|
|
HexColors = {
|
|
|
|
TileType.None: NoneColors,
|
|
|
|
TileType.Sand: SandColors,
|
2022-01-06 22:26:53 +01:00
|
|
|
TileType.Grass: GrassColors,
|
|
|
|
TileType.DeepGrass: DeepGrassColors
|
2021-06-28 21:51:09 +02:00
|
|
|
}
|
|
|
|
|
2021-07-11 16:09:04 +02:00
|
|
|
func create_color_array(color: Color):
|
|
|
|
var result = PoolColorArray()
|
|
|
|
for _i in range (7):
|
|
|
|
result.append(color)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2021-06-28 21:51:09 +02:00
|
|
|
func get_tile_color (type_name: String):
|
|
|
|
match type_name:
|
|
|
|
"None": return HexColors[TileType.None]
|
|
|
|
"Sand": return HexColors[TileType.Sand]
|
|
|
|
"Grass": return HexColors[TileType.Grass]
|
2022-01-06 22:26:53 +01:00
|
|
|
"DeepGrass": return HexColors[TileType.DeepGrass]
|
2021-06-28 21:51:09 +02:00
|
|
|
_ : return null
|