From b7f765ebe28dd8dea3e4c094c46681fdfec56fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 21 Jul 2020 09:16:24 +0200 Subject: =?UTF-8?q?HexMap.configure(=E2=80=A6)=20->=20HexMap.=5Finit(?= =?UTF-8?q?=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HexMap.gd | 3 ++- demo/Map.gd | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/HexMap.gd b/HexMap.gd index 7520972..2fb8a15 100644 --- a/HexMap.gd +++ b/HexMap.gd @@ -28,7 +28,8 @@ var adjacents : Array var search_count : int var stack : Array -func configure(cols : int, rows : int, side : float, v0 : Vector2, vertical : bool) -> void: +func _init(cols : int, rows : int, side : float, v0 : Vector2, vertical : bool, fct : FuncRef) -> void: + tile_factory_fct = fct v = vertical s = side w = s * 1.73205 diff --git a/demo/Map.gd b/demo/Map.gd index 81c5c36..22ad0fd 100644 --- a/demo/Map.gd +++ b/demo/Map.gd @@ -34,9 +34,6 @@ var show_influence : bool func _ready(): drag = null unit = Unit.new() - board = HexBoard.new() - board.tile_factory_fct = funcref(self, "get_tile") - board.v = false rotate_map() func reset() -> void: @@ -56,7 +53,7 @@ func reset() -> void: compute() func rotate_map() -> void: - texture = load(MAPH if board.v else MAPV) + texture = load(MAPH if is_instance_valid(board) and board.v else MAPV) configure() reset() @@ -67,20 +64,21 @@ func set_mode(l : bool, m : bool, i : bool) -> void: compute() func configure() -> void: + var v : bool = (is_instance_valid(board) and board.v) var v0 : Vector2 = Vector2(50, 100) if centered: var ts : Vector2 = texture.get_size() - if board.v: + if v: v0.x -= ts.y / 2 v0.y -= ts.x / 2 else: v0 -= ts / 2 - if board.v: + if v: hex_rotation = 30 - board.configure(10, 4, 100, v0, false) + board = HexBoard.new(10, 4, 100, v0, false, funcref(self, "get_tile")) else: hex_rotation = 0 - board.configure(10, 7, 100, v0, true) + board = HexBoard.new(10, 7, 100, v0, true, funcref(self, "get_tile")) func texture_size() -> Vector2: return texture.get_size() -- cgit v1.1-2-g2b99