From 54311e2b4194ccad0d28b60a718da8cb01c89f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 28 Aug 2021 11:07:19 +0200 Subject: set addons/hexgrid, closess #2 --- .gdignore | 1 - .gitattributes | 1 - HexMap.gd | 530 --------------------------------------- Piece.gd | 35 --- Tile.gd | 49 ---- addons/hexgrid/HexMap.gd | 530 +++++++++++++++++++++++++++++++++++++++ addons/hexgrid/HexMap.png | Bin 0 -> 14569 bytes addons/hexgrid/HexMap.png.import | 35 +++ addons/hexgrid/Piece.gd | 35 +++ addons/hexgrid/Piece.png | Bin 0 -> 14747 bytes addons/hexgrid/Piece.png.import | 35 +++ addons/hexgrid/Tile.gd | 49 ++++ addons/hexgrid/Tile.png | Bin 0 -> 14150 bytes addons/hexgrid/Tile.png.import | 35 +++ assets/Anke.otf | Bin 24364 -> 0 bytes assets/black.png | Bin 2868 -> 0 bytes assets/black.png.import | 34 --- assets/block.png | Bin 5029 -> 0 bytes assets/block.png.import | 34 --- assets/city.png | Bin 14508 -> 0 bytes assets/city.png.import | 34 --- assets/green.png | Bin 6204 -> 0 bytes assets/green.png.import | 34 --- assets/map-h.png | Bin 18756 -> 0 bytes assets/map-h.png.import | 34 --- assets/map-v.png | Bin 73999 -> 0 bytes assets/map-v.png.import | 34 --- assets/mountain.png | Bin 13386 -> 0 bytes assets/mountain.png.import | 34 --- assets/move.png | Bin 5145 -> 0 bytes assets/move.png.import | 34 --- assets/red.png | Bin 4526 -> 0 bytes assets/red.png.import | 34 --- assets/short.png | Bin 1188 -> 0 bytes assets/short.png.import | 34 --- assets/tank.png | Bin 10024 -> 0 bytes assets/tank.png.import | 34 --- assets/target.png | Bin 8674 -> 0 bytes assets/target.png.import | 34 --- assets/tree.png | Bin 13687 -> 0 bytes assets/tree.png.import | 34 --- demo/Hex.gd | 2 +- demo/Main.tscn | 6 +- demo/Map.gd | 22 +- demo/Unit.gd | 2 +- demo/assets/Anke.otf | Bin 0 -> 24364 bytes demo/assets/black.png | Bin 0 -> 2868 bytes demo/assets/black.png.import | 35 +++ demo/assets/block.png | Bin 0 -> 5029 bytes demo/assets/block.png.import | 35 +++ demo/assets/city.png | Bin 0 -> 14508 bytes demo/assets/city.png.import | 35 +++ demo/assets/green.png | Bin 0 -> 6204 bytes demo/assets/green.png.import | 35 +++ demo/assets/map-h.png | Bin 0 -> 18756 bytes demo/assets/map-h.png.import | 35 +++ demo/assets/map-v.png | Bin 0 -> 73999 bytes demo/assets/map-v.png.import | 35 +++ demo/assets/mountain.png | Bin 0 -> 13386 bytes demo/assets/mountain.png.import | 35 +++ demo/assets/move.png | Bin 0 -> 5145 bytes demo/assets/move.png.import | 35 +++ demo/assets/red.png | Bin 0 -> 4526 bytes demo/assets/red.png.import | 35 +++ demo/assets/short.png | Bin 0 -> 1188 bytes demo/assets/short.png.import | 35 +++ demo/assets/tank.png | Bin 0 -> 10024 bytes demo/assets/tank.png.import | 35 +++ demo/assets/target.png | Bin 0 -> 8674 bytes demo/assets/target.png.import | 35 +++ demo/assets/tree.png | Bin 0 -> 13687 bytes demo/assets/tree.png.import | 35 +++ godot/HexMap.png | Bin 14569 -> 0 bytes godot/HexMap.png.import | 35 --- godot/Piece.png | Bin 14747 -> 0 bytes godot/Piece.png.import | 35 --- godot/Tile.png | Bin 14150 -> 0 bytes godot/Tile.png.import | 35 --- project.godot | 16 +- 79 files changed, 1198 insertions(+), 1187 deletions(-) delete mode 100644 HexMap.gd delete mode 100644 Piece.gd delete mode 100644 Tile.gd create mode 100644 addons/hexgrid/HexMap.gd create mode 100644 addons/hexgrid/HexMap.png create mode 100644 addons/hexgrid/HexMap.png.import create mode 100644 addons/hexgrid/Piece.gd create mode 100644 addons/hexgrid/Piece.png create mode 100644 addons/hexgrid/Piece.png.import create mode 100644 addons/hexgrid/Tile.gd create mode 100644 addons/hexgrid/Tile.png create mode 100644 addons/hexgrid/Tile.png.import delete mode 100644 assets/Anke.otf delete mode 100644 assets/black.png delete mode 100644 assets/black.png.import delete mode 100644 assets/block.png delete mode 100644 assets/block.png.import delete mode 100644 assets/city.png delete mode 100644 assets/city.png.import delete mode 100644 assets/green.png delete mode 100644 assets/green.png.import delete mode 100644 assets/map-h.png delete mode 100644 assets/map-h.png.import delete mode 100644 assets/map-v.png delete mode 100644 assets/map-v.png.import delete mode 100644 assets/mountain.png delete mode 100644 assets/mountain.png.import delete mode 100644 assets/move.png delete mode 100644 assets/move.png.import delete mode 100644 assets/red.png delete mode 100644 assets/red.png.import delete mode 100644 assets/short.png delete mode 100644 assets/short.png.import delete mode 100644 assets/tank.png delete mode 100644 assets/tank.png.import delete mode 100644 assets/target.png delete mode 100644 assets/target.png.import delete mode 100644 assets/tree.png delete mode 100644 assets/tree.png.import create mode 100644 demo/assets/Anke.otf create mode 100644 demo/assets/black.png create mode 100644 demo/assets/black.png.import create mode 100644 demo/assets/block.png create mode 100644 demo/assets/block.png.import create mode 100644 demo/assets/city.png create mode 100644 demo/assets/city.png.import create mode 100644 demo/assets/green.png create mode 100644 demo/assets/green.png.import create mode 100644 demo/assets/map-h.png create mode 100644 demo/assets/map-h.png.import create mode 100644 demo/assets/map-v.png create mode 100644 demo/assets/map-v.png.import create mode 100644 demo/assets/mountain.png create mode 100644 demo/assets/mountain.png.import create mode 100644 demo/assets/move.png create mode 100644 demo/assets/move.png.import create mode 100644 demo/assets/red.png create mode 100644 demo/assets/red.png.import create mode 100644 demo/assets/short.png create mode 100644 demo/assets/short.png.import create mode 100644 demo/assets/tank.png create mode 100644 demo/assets/tank.png.import create mode 100644 demo/assets/target.png create mode 100644 demo/assets/target.png.import create mode 100644 demo/assets/tree.png create mode 100644 demo/assets/tree.png.import delete mode 100644 godot/HexMap.png delete mode 100644 godot/HexMap.png.import delete mode 100644 godot/Piece.png delete mode 100644 godot/Piece.png.import delete mode 100644 godot/Tile.png delete mode 100644 godot/Tile.png.import diff --git a/.gdignore b/.gdignore index 7454c37..c78e003 100644 --- a/.gdignore +++ b/.gdignore @@ -1,3 +1,2 @@ -assets data demo diff --git a/.gitattributes b/.gitattributes index 5813cb7..6f20e8e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,6 +10,5 @@ /default_env.tres export-ignore /project.godot export-ignore /icon.png* export-ignore -/assets export-ignore /data export-ignore /demo export-ignore diff --git a/HexMap.gd b/HexMap.gd deleted file mode 100644 index c719b20..0000000 --- a/HexMap.gd +++ /dev/null @@ -1,530 +0,0 @@ -#warning-ignore-all:integer_division -extends Node - -class_name HexBoard, "res://godot/HexMap.png" - -enum Orientation { E=1, NE=2, N=4, NW=8, W=16, SW=32, S=64, SE=128 } - -const IMAX : int = 9999999999 -const DEGREE_ADJ : int = 2 - -var bt : Vector2 # bottom corner -var cr : Vector2 # column, row - -var v : bool # hex have a vertical edje - -var s : float # hex side length -var w : float # hex width between 2 parallel sides -var h : float # hex height from the bottom of the middle rectangle to the top of the upper edje -var dw : float # half width -var dh : float # half height (from the top ef tho middle rectangle to the top of the upper edje) -var m : float # dh / dw -var im : float # dw / dh -var tl : int # num of hexes in 2 consecutives rows - -var tile_factory_fct : FuncRef -var angles : Dictionary -var adjacents : Array -var search_count : int -var stack : Array - -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 - dw = w / 2.0 - dh = s / 2.0 - h = s + dh - m = dh / dw - im = dw / dh - if v: - bt = v0 - cr = Vector2(cols, rows) - else: - bt = v0 - cr = Vector2(rows, cols) - tl = (2 * int(cr.x) - 1) - search_count = 0 - angles = {} - if v: - # origin [top-left] East is at 0°, degrees grows clockwise - angles[Orientation.E] = 0 - angles[Orientation.SE] = 60 - angles[Orientation.SW] = 120 - angles[Orientation.W] = 180 - angles[Orientation.NW] = 240 - angles[Orientation.NE] = 300 - else: - angles[Orientation.SE] = 30 - angles[Orientation.S] = 90 - angles[Orientation.SW] = 150 - angles[Orientation.NW] = 210 - angles[Orientation.N] = 270 - angles[Orientation.NE] = 330 - -# the number of Tile -func size() -> int: - return int(cr.y) / 2 * tl + int(cr.y) % 2 * int(cr.x) - -# fetch a Tile given it's col;row coordinates -func get_tile(coords : Vector2) -> Tile: - return tile_factory_fct.call_func(coords, key(coords)) - -# Orientation to degrees -func to_degrees(o : int) -> int: - return angles.get(o, -1) - -# convert the given angle between 2 adjacent Tiles into an Orientation -func to_orientation(a : float) -> int: - for k in angles.keys(): - if angles[k] == a: - return k - return -1 - -# compute the angle between 2 adjacent Tiles -func angle(from : Tile, to : Tile) -> int: - var a : float = rad2deg((to.position - from.position).angle()) + DEGREE_ADJ - if a < 0: a += 360 - return int(a / 10) * 10 - -# return the opposite of a given Orientation -func opposite(o : int) -> int: - if o <= Orientation.NW: return o << 4 - return o >> 4 - -# return the Orientation given to distant Tiles -# Orientation is combined in case of diagonals -func distant_orientation(from : Tile, to : Tile) -> int: - var a : float = rad2deg((to.position - from.position).angle()) - if a < 0: a += 360 - a = int(a * 10) / 10.0 - for k in angles.keys(): - var z : int = angles[k] - if a >= (z + 30 - DEGREE_ADJ) and a <= (z + 30 + DEGREE_ADJ): - # diagonal - var p : int = k >> 1 - if p == 0: p = Orientation.SE - if not angles.has(p): return k | p >> 1 # v : N S and not v : W E - else: return (k | p) - elif (z == 30 and (a < DEGREE_ADJ or a > 360 - DEGREE_ADJ)): - return Orientation.NE | Orientation.SE - elif a >= (z - 30) and a <= (z + 30): - return k - if angles.has(Orientation.E) and a > 330 and a <= 360: - return Orientation.E - return -1 - -# return the opposite of a possibly combined given Orientation -func distant_opposite(o : int) -> int: - var r : int = 0 - for k in angles.keys(): - if (k & o) == k: - r |= opposite(k) - return r - -# return the key of a given col;row coordinate -func key(coords : Vector2) -> int: - if not is_on_map(coords): return -1 - if v: return _key(int(coords.x), int(coords.y)) - else: return _key(int(coords.y), int(coords.x)) - -func _key(x : int, y : int) -> int: - var n : int = y / 2 - var i : int = x - n + n * tl - if (y % 2) != 0: - i += (int(cr.x) - 1) - return i - -# build the 6 adjacent Tiles of a Tile given by it's col;row coordinates -func adjacents_of(tile : Tile, tiles : Array) -> void: - tiles.clear() - for t in _build_adjacents(tile.coords): tiles.append(t) - -func _build_adjacents(coords : Vector2) -> Array: - adjacents.clear() - coords.x += 1 - adjacents.append(get_tile(coords)) - coords.y += 1 - adjacents.append(get_tile(coords)) - coords.x -= 1 - adjacents.append(get_tile(coords)) - coords.x -= 1 - coords.y -= 1 - adjacents.append(get_tile(coords)) - coords.y -= 1 - adjacents.append(get_tile(coords)) - coords.x += 1 - adjacents.append(get_tile(coords)) - return adjacents - -# return true if the Tile is on the map -func is_on_map(coords : Vector2) -> bool: - if v: return _is_on_map(int(coords.x), int(coords.y)) - else: return _is_on_map(int(coords.y), int(coords.x)) - -func _is_on_map(x : int, y : int) -> bool: - if (y < 0) || (y >= int(cr.y)): return false - if (x < ((y + 1) / 2)) || (x >= (int(cr.x) + (y / 2))): return false - return true - -# compute the center of a Tile given by it's col;row coordinates -func center_of(coords : Vector2) -> Vector2: - if v: return Vector2(bt.x + dw + (coords.x * w) - (coords.y * dw), bt.y + dh + (coords.y * h)) - else: return Vector2(bt.y + dh + (coords.x * h), bt.x + dw + (coords.y * w) - (coords.x * dw)) - -# compute the col;row coordinates of a Tile given it's real coordinates -func to_map(r : Vector2) -> Vector2: - if v: return _to_map(r.x, r.y, false) - else: return _to_map(r.y, r.x, true) - -func _to_map(x : float, y : float, swap : bool) -> Vector2: - var col : int = -1 - var row : int = -1 - # compute row - var dy : float = y - bt.y - row = int(dy / h) - if dy < 0: - row -= 1 - # compute col - var dx : float = x - bt.x + (row * dw); - col = int(dx / w) - if dx < 0: - col -= 1 - # upper rectangle or hex body - if dy > ((row * h) + s): - dy -= ((row * h) + s) - dx -= (col * w) - # upper left or right rectangle - if dx < dw: - if dy > (dx * m): - # upper left hex - row += 1 - else: - if dy > ((w - dx) * m): - # upper right hex - row += 1 - col += 1 - if swap: return Vector2(row, col) - else: return Vector2(col, row) - -# compute the distance between 2 Tiles given by their col;row coordinates -func distance(p0 : Vector2, p1 : Vector2, euclidean : bool = true) -> float: - var dx : int = int(p1.x - p0.x) - var dy : int = int(p1.y - p0.y) - if euclidean: - if dx == 0: return abs(dy) - elif dy == 0 || dx == dy: return abs(dx) - var fdx : float = dx - dy / 2; - var fdy : float = dy * 0.86602 - return sqrt((fdx * fdx) + (fdy * fdy)) - else: - dx = int(abs(dx)) - dy = int(abs(dy)) - var dz : float = abs(p1.x - p0.x - p1.y + p0.y) - if dx > dy: - if dx > dz: return float(dx) - else: - if dy > dz: return float(dy) - return dz - -# http://zvold.blogspot.com/2010/01/bresenhams-line-drawing-algorithm-on_26.html -# http://zvold.blogspot.com/2010/02/line-of-sight-on-hexagonal-grid.html -# compute as an Array, the line of sight between 2 Tiles given by their col;row coordinates -# return the point after which the line of sight is blocked -func line_of_sight(p0 : Vector2, p1 : Vector2, tiles : Array) -> Vector2: - tiles.clear() - # orthogonal projection - var ox0 : float = p0.x - (p0.y + 1) / 2 - var ox1 : float = p1.x - (p1.y + 1) / 2 - var dy : int = int(p1.y) - int(p0.y) - var dx : float = ox1 - ox0 - # quadrant I && III - var q13 : bool = (dx >= 0 && dy >= 0) || (dx < 0 && dy < 0) - # is positive - var xs : int = 1 - var ys : int = 1 - if dx < 0: xs = -1 - if dy < 0: ys = -1 - # dx counts half width - dy = int(abs(dy)) - dx = abs(2 * dx) - var dx3 : int = int(3 * dx) - var dy3 : int = 3 * dy - # check for diagonals - if dx == 0 || dx == dy3: - return _diagonal_los(p0, p1, (dx == 0), q13, tiles) - # angle is less than 45° - var flat : bool = dx > dy3 - var x : int = int(p0.x) - var y : int = int(p0.y); - var e : int = int(-2 * dx) - var from : Tile = get_tile(p0) - var to : Tile = get_tile(p1) - var d : float = distance(p0, p1) - tiles.append(from) - from.blocked = false - var ret : Vector2 = Vector2(-1, -1) - var contact : bool = false - var los_blocked : bool = false - while (x != p1.x) or (y != p1.y): - if e > 0: - # quadrant I : up left - e -= (dy3 + dx3) - y += ys - if not q13: x -= xs - else: - e += dy3 - if (e > -dx) or (not flat && (e == -dx)): - # quadrant I : up right - e -= dx3 - y += ys - if q13: x += xs - elif e < -dx3: - # quadrant I : down right - e += dx3 - y -= ys - if not q13: x += xs - else: - # quadrant I : right - e += dy3 - x += xs - var q : Vector2 = Vector2(x, y) - var t : Tile = get_tile(q) - if los_blocked and not contact: - var prev : Tile = tiles[tiles.size() - 1] - var o : int = to_orientation(angle(prev, t)) - ret = _compute_contact(from.position, to.position, prev.position, o) - contact = true - tiles.append(t) - t.blocked = los_blocked - los_blocked = los_blocked or t.block_los(from, to, d, distance(p0, q)) - return ret - -func _diagonal_los(p0 : Vector2, p1 : Vector2, flat : bool, q13 : bool, tiles : Array) -> Vector2: - var dy : int = 1 if p1.y > p0.y else -1 - var dx : int = 1 if p1.x > p0.x else -1 - var x : int = int(p0.x) - var y : int = int(p0.y) - var from : Tile = get_tile(p0); - var to : Tile = get_tile(p1); - var d : float = distance(p0, p1) - tiles.append(from); - from.blocked = false; - var ret : Vector2 = Vector2(-1, -1) - var blocked : int = 0 - var contact : bool = false - var los_blocked : bool = false - while (x != p1.x) or (y != p1.y): - var idx : int = 4 - if flat: y += dy # up left - else: x += dx # right - var q : Vector2 = Vector2(x, y) - var t : Tile = get_tile(q) - if t.on_map: - tiles.append(t) - t.blocked = los_blocked - if t.block_los(from, to, d, distance(p0, q)): - blocked |= 0x01 - else: - blocked |= 0x01 - idx = 3 - - if flat: x += dx # up right - else: - y += dy # up right - if not q13: x -= dx - q = Vector2(x, y) - t = get_tile(q) - if t.on_map: - tiles.append(t) - t.blocked = los_blocked - if t.block_los(from, to, d, distance(p0, q)): - blocked |= 0x02 - else: - blocked |= 0x02 - idx = 3 - - if flat: y += dy # up - else: x += dx # diagonal - q = Vector2(x, y) - t = get_tile(q) - tiles.append(t) - t.blocked = los_blocked || blocked == 0x03 - if t.blocked and not contact: - var o : int = _compute_orientation(dx, dy, flat) - if not los_blocked and blocked == 0x03: - ret = _compute_contact(from.position, to.position, t.position, opposite(o)) - else: - ret = _compute_contact(from.position, to.position, tiles[tiles.size() - idx].position, o) - contact = true; - los_blocked = t.blocked || t.block_los(from, to, d, distance(p0, q)) - return ret - -func _compute_orientation(dx :int, dy :int, flat : bool) -> int: - if flat: - if v: return Orientation.S if dy == 1 else Orientation.N - else: return Orientation.S if dx == 1 else Orientation.N - if dx == 1: - if dy == 1: return Orientation.E - else: return Orientation.E if v else Orientation.N - else: - if dy == 1: return Orientation.W if v else Orientation.S - else: return Orientation.W - -func _compute_contact(from : Vector2, to : Vector2, t : Vector2, o : int) -> Vector2: - var dx : float = to.x - from.x - var dy : float = to.y - from.y - var n : float = float(IMAX) if dx == 0 else (dy / dx) - var c : float = from.y - (n * from.x) - if v: - if o == Orientation.N: return Vector2(t.x, t.y - s) - elif o == Orientation.S: return Vector2(t.x, t.y + s) - elif o == Orientation.E: - var x : float = t.x + dw - return Vector2(x, from.y + n * (x - from.x)) - elif o == Orientation.W: - var x : float = t.x - dw - return Vector2(x, from.y + n * (x - from.x)) - else: - var p : float = -m if (o == Orientation.SE or o == Orientation.NW) else m - var k : float = t.y - p * t.x - if o == Orientation.SE || o == Orientation.SW: k += s - else: k -= s - var x : float = (k - c) / (n - p) - return Vector2(x, n * x + c) - else: - if o == Orientation.E: return Vector2(t.x + s, t.y) - elif o == Orientation.W: return Vector2(t.x - s, t.y) - elif o == Orientation.N: - var y : float = t.y - dw - return Vector2(from.x + (y - from.y) / n, y) - elif o == Orientation.S: - var y : float = t.y + dw - return Vector2(from.x + (y - from.y) / n, y) - else: - var p : float = -im if (o == Orientation.SE or o == Orientation.NW) else +im - var k : float = 0 - if o == Orientation.SW or o == Orientation.NW: k = t.y - (p * (t.x - s)) - else: k = t.y - (p * (t.x + s)) - var x : float = (k - c) / (n - p) - return Vector2(x, n * x + c); - -# compute as an Array, the Tiles that can be reached by a given Piece from a Tile given by it's col;row coordinates -# return the size of the built Array -func possible_moves(piece : Piece, from : Tile, tiles : Array) -> int: - tiles.clear() - if piece.get_mp() <= 0 or not is_on_map(from.coords): return 0 - var road_march_bonus : int = piece.road_march_bonus() - search_count += 1 - from.parent = null - from.acc = piece.get_mp() - from.search_count = search_count - from.road_march = road_march_bonus > 0 - stack.push_back(from) - while(not stack.empty()): - var src : Tile = stack.pop_back() - if (src.acc + (road_march_bonus if src.road_march else 0)) <= 0: continue - # warning-ignore:return_value_discarded - _build_adjacents(src.coords) - for dst in adjacents: - if not dst.on_map: continue - var o : int = to_orientation(angle(src, dst)) - var cost : int = piece.move_cost(src, dst, o) - if (cost == -1): continue # impracticable - var r : int = src.acc - cost - var rm : bool = src.road_march and src.has_road(o) - # not enough MP even with RM, maybe first move allowed - if ((r + (road_march_bonus if rm else 0)) < 0 and not (src == from and piece.at_least_one_tile(dst))): continue - if dst.search_count != search_count: - dst.search_count = search_count - dst.acc = r - dst.parent = src - dst.road_march = rm - stack.push_back(dst) - tiles.append(dst) - elif (r > dst.acc or (rm and (r + road_march_bonus > dst.acc + (road_march_bonus if dst.road_march else 0)))): - dst.acc = r - dst.parent = src - dst.road_march = rm - stack.push_back(dst) - return tiles.size() - -# compute as an Array, the shortest path for a given Piece from a Tile to another given by there col;row coordinates -# return the size of the built Array -func shortest_path(piece : Piece, from : Tile, to : Tile, tiles : Array) -> int: - tiles.clear() - if from == to or not is_on_map(from.coords) or not is_on_map(to.coords): return tiles.size() - var road_march_bonus : int = piece.road_march_bonus() - search_count += 1 - from.acc = 0 - from.parent = null - from.search_count = search_count - from.road_march = road_march_bonus > 0 - stack.push_back(from) - while(not stack.empty()): - var src : Tile = stack.pop_back() - if (src == to): break - # warning-ignore:return_value_discarded - _build_adjacents(src.coords) - for dst in adjacents: - if not dst.on_map: continue - var o : int = to_orientation(angle(src, dst)) - var cost : int = piece.move_cost(src, dst, o) - if (cost == -1): continue # impracticable - cost += src.acc - var total : float = cost + distance(dst.coords, to.coords) - var rm : bool = src.road_march and src.has_road(o) - if rm: total -= road_march_bonus - var add : bool = false - if dst.search_count != search_count: - dst.search_count = search_count - add = true - elif dst.f > total or (rm and not dst.road_march and abs(dst.f - total) < 0.001): - stack.erase(dst) - add = true - if add: - dst.acc = cost - dst.f = total - dst.road_march = rm - dst.parent = src - var idx : int = IMAX - for k in range(stack.size()): - if stack[k].f <= dst.f: - idx = k - break - if idx == IMAX: stack.push_back(dst) - else: stack.insert(idx, dst) - stack.clear() - if to.search_count == search_count: - var t : Tile = to - while t != from: - tiles.push_front(t) - t = t.parent - tiles.push_front(from) - return tiles.size() - -func range_of_influence(piece : Piece, from : Tile, category : int, tiles : Array) -> int: - tiles.clear() - var max_range : int = piece.max_range_of_fire(category, from) - if not is_on_map(from.coords): return 0 - var tmp : Array = [] - search_count += 1 - from.search_count = search_count - stack.push_back(from) - while(not stack.empty()): - var src : Tile = stack.pop_back() - # warning-ignore:return_value_discarded - _build_adjacents(src.coords) - for dst in adjacents: - if not dst.on_map: continue - if dst.search_count == search_count: continue - dst.search_count = search_count - var d : int = int(distance(from.coords, dst.coords, false)) - if d > max_range: continue - if line_of_sight(from.coords, dst.coords, tmp).x != -1: continue - var o : int = distant_orientation(from, dst) - dst.f = piece.volume_of_fire(category, d, from, o, dst, distant_opposite(o)) - stack.push_back(dst) - tiles.append(dst) - return tiles.size() diff --git a/Piece.gd b/Piece.gd deleted file mode 100644 index 8725cc2..0000000 --- a/Piece.gd +++ /dev/null @@ -1,35 +0,0 @@ -#warning-ignore-all:unused_argument -extends Node2D - -class_name Piece, "res://godot/Piece.png" - -# movement points -func get_mp() -> int: - print("Piece#get_mp() must be overriden in a subclass") - return 0 - -# movement point bonus if you start your movement on a road and follow it -func road_march_bonus() -> int: - print("Piece#road_march_bonus() must be overriden in a subclass") - return 0 - -# movement cost from a Tile to another adjacent Tile -func move_cost(src : Tile, dst : Tile, orientation : int) -> int: - print("Piece#move_cost() must be overriden in a subclass") - return -1 # impracticable - -# are you allowed to move into that Tile as only move even if you don't have enough movement points -func at_least_one_tile(dst : Tile) -> bool: - print("Piece#at_least_one_tile() must be overriden in a subclass") - return true - -# the maximum range of fire with a given category of weapon -func max_range_of_fire(category : int, from : Tile) -> int: - print("Piece#max_range_of_fire() must be overriden in a subclass") - return 0 - -# the projected volume of fire with a given category of weapon at a given distance, -# out of a given Tile with a given orientation, into a given Tile with a given orientation -func volume_of_fire(category : int, distance : int, src : Tile, src_o : int, dst : Tile, dst_o : int) -> int: - print("Piece#volume_of_fire() must be overriden in a subclass") - return -1 # out of range diff --git a/Tile.gd b/Tile.gd deleted file mode 100644 index 68627f4..0000000 --- a/Tile.gd +++ /dev/null @@ -1,49 +0,0 @@ -#warning-ignore-all:unused_argument -extends Node2D - -class_name Tile, "res://godot/Tile.png" - -var coords : Vector2 -var blocked : bool -var on_map : bool = false - -var acc : int -var f : float -var parent : Tile -var road_march : bool -var search_count : int - -func configure(p : Vector2, c: Vector2, o :Array) -> void: - position = p - coords = c - on_map = true - for t in o: - var s :Sprite = Sprite.new() - s.texture = load(t) - s.visible = false - add_child(s) - visible = false - -# is there a road with given orientation that drives out of that Tile -func has_road(orientation : int) -> bool: - print("Tile#has_road() must be overriden in a subclass") - return false - -# is the line of sight blocked from a Tile to another, d beeing the distance between from and to, -# dt beeing the distance between from and this Tile -func block_los(from : Tile, to : Tile, d : float, dt : float) -> bool: - print("Tile#block_los() must be overriden in a subclass") - return false - -func enable_overlay(i :int, v : bool) -> void: - get_child(i).visible = v - if v: visible = true - else : - visible = false - for o in get_children(): - if o.visible: - visible = true - break - -func is_overlay_on(i) -> bool: - return get_child(i).visible diff --git a/addons/hexgrid/HexMap.gd b/addons/hexgrid/HexMap.gd new file mode 100644 index 0000000..3da1631 --- /dev/null +++ b/addons/hexgrid/HexMap.gd @@ -0,0 +1,530 @@ +#warning-ignore-all:integer_division +extends Node + +class_name HexBoard, "res://addons/hexgrid/HexMap.png" + +enum Orientation { E=1, NE=2, N=4, NW=8, W=16, SW=32, S=64, SE=128 } + +const IMAX : int = 9999999999 +const DEGREE_ADJ : int = 2 + +var bt : Vector2 # bottom corner +var cr : Vector2 # column, row + +var v : bool # hex have a vertical edje + +var s : float # hex side length +var w : float # hex width between 2 parallel sides +var h : float # hex height from the bottom of the middle rectangle to the top of the upper edje +var dw : float # half width +var dh : float # half height (from the top ef tho middle rectangle to the top of the upper edje) +var m : float # dh / dw +var im : float # dw / dh +var tl : int # num of hexes in 2 consecutives rows + +var tile_factory_fct : FuncRef +var angles : Dictionary +var adjacents : Array +var search_count : int +var stack : Array + +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 + dw = w / 2.0 + dh = s / 2.0 + h = s + dh + m = dh / dw + im = dw / dh + if v: + bt = v0 + cr = Vector2(cols, rows) + else: + bt = v0 + cr = Vector2(rows, cols) + tl = (2 * int(cr.x) - 1) + search_count = 0 + angles = {} + if v: + # origin [top-left] East is at 0°, degrees grows clockwise + angles[Orientation.E] = 0 + angles[Orientation.SE] = 60 + angles[Orientation.SW] = 120 + angles[Orientation.W] = 180 + angles[Orientation.NW] = 240 + angles[Orientation.NE] = 300 + else: + angles[Orientation.SE] = 30 + angles[Orientation.S] = 90 + angles[Orientation.SW] = 150 + angles[Orientation.NW] = 210 + angles[Orientation.N] = 270 + angles[Orientation.NE] = 330 + +# the number of Tile +func size() -> int: + return int(cr.y) / 2 * tl + int(cr.y) % 2 * int(cr.x) + +# fetch a Tile given it's col;row coordinates +func get_tile(coords : Vector2) -> Tile: + return tile_factory_fct.call_func(coords, key(coords)) + +# Orientation to degrees +func to_degrees(o : int) -> int: + return angles.get(o, -1) + +# convert the given angle between 2 adjacent Tiles into an Orientation +func to_orientation(a : float) -> int: + for k in angles.keys(): + if angles[k] == a: + return k + return -1 + +# compute the angle between 2 adjacent Tiles +func angle(from : Tile, to : Tile) -> int: + var a : float = rad2deg((to.position - from.position).angle()) + DEGREE_ADJ + if a < 0: a += 360 + return int(a / 10) * 10 + +# return the opposite of a given Orientation +func opposite(o : int) -> int: + if o <= Orientation.NW: return o << 4 + return o >> 4 + +# return the Orientation given to distant Tiles +# Orientation is combined in case of diagonals +func distant_orientation(from : Tile, to : Tile) -> int: + var a : float = rad2deg((to.position - from.position).angle()) + if a < 0: a += 360 + a = int(a * 10) / 10.0 + for k in angles.keys(): + var z : int = angles[k] + if a >= (z + 30 - DEGREE_ADJ) and a <= (z + 30 + DEGREE_ADJ): + # diagonal + var p : int = k >> 1 + if p == 0: p = Orientation.SE + if not angles.has(p): return k | p >> 1 # v : N S and not v : W E + else: return (k | p) + elif (z == 30 and (a < DEGREE_ADJ or a > 360 - DEGREE_ADJ)): + return Orientation.NE | Orientation.SE + elif a >= (z - 30) and a <= (z + 30): + return k + if angles.has(Orientation.E) and a > 330 and a <= 360: + return Orientation.E + return -1 + +# return the opposite of a possibly combined given Orientation +func distant_opposite(o : int) -> int: + var r : int = 0 + for k in angles.keys(): + if (k & o) == k: + r |= opposite(k) + return r + +# return the key of a given col;row coordinate +func key(coords : Vector2) -> int: + if not is_on_map(coords): return -1 + if v: return _key(int(coords.x), int(coords.y)) + else: return _key(int(coords.y), int(coords.x)) + +func _key(x : int, y : int) -> int: + var n : int = y / 2 + var i : int = x - n + n * tl + if (y % 2) != 0: + i += (int(cr.x) - 1) + return i + +# build the 6 adjacent Tiles of a Tile given by it's col;row coordinates +func adjacents_of(tile : Tile, tiles : Array) -> void: + tiles.clear() + for t in _build_adjacents(tile.coords): tiles.append(t) + +func _build_adjacents(coords : Vector2) -> Array: + adjacents.clear() + coords.x += 1 + adjacents.append(get_tile(coords)) + coords.y += 1 + adjacents.append(get_tile(coords)) + coords.x -= 1 + adjacents.append(get_tile(coords)) + coords.x -= 1 + coords.y -= 1 + adjacents.append(get_tile(coords)) + coords.y -= 1 + adjacents.append(get_tile(coords)) + coords.x += 1 + adjacents.append(get_tile(coords)) + return adjacents + +# return true if the Tile is on the map +func is_on_map(coords : Vector2) -> bool: + if v: return _is_on_map(int(coords.x), int(coords.y)) + else: return _is_on_map(int(coords.y), int(coords.x)) + +func _is_on_map(x : int, y : int) -> bool: + if (y < 0) || (y >= int(cr.y)): return false + if (x < ((y + 1) / 2)) || (x >= (int(cr.x) + (y / 2))): return false + return true + +# compute the center of a Tile given by it's col;row coordinates +func center_of(coords : Vector2) -> Vector2: + if v: return Vector2(bt.x + dw + (coords.x * w) - (coords.y * dw), bt.y + dh + (coords.y * h)) + else: return Vector2(bt.y + dh + (coords.x * h), bt.x + dw + (coords.y * w) - (coords.x * dw)) + +# compute the col;row coordinates of a Tile given it's real coordinates +func to_map(r : Vector2) -> Vector2: + if v: return _to_map(r.x, r.y, false) + else: return _to_map(r.y, r.x, true) + +func _to_map(x : float, y : float, swap : bool) -> Vector2: + var col : int = -1 + var row : int = -1 + # compute row + var dy : float = y - bt.y + row = int(dy / h) + if dy < 0: + row -= 1 + # compute col + var dx : float = x - bt.x + (row * dw); + col = int(dx / w) + if dx < 0: + col -= 1 + # upper rectangle or hex body + if dy > ((row * h) + s): + dy -= ((row * h) + s) + dx -= (col * w) + # upper left or right rectangle + if dx < dw: + if dy > (dx * m): + # upper left hex + row += 1 + else: + if dy > ((w - dx) * m): + # upper right hex + row += 1 + col += 1 + if swap: return Vector2(row, col) + else: return Vector2(col, row) + +# compute the distance between 2 Tiles given by their col;row coordinates +func distance(p0 : Vector2, p1 : Vector2, euclidean : bool = true) -> float: + var dx : int = int(p1.x - p0.x) + var dy : int = int(p1.y - p0.y) + if euclidean: + if dx == 0: return abs(dy) + elif dy == 0 || dx == dy: return abs(dx) + var fdx : float = dx - dy / 2; + var fdy : float = dy * 0.86602 + return sqrt((fdx * fdx) + (fdy * fdy)) + else: + dx = int(abs(dx)) + dy = int(abs(dy)) + var dz : float = abs(p1.x - p0.x - p1.y + p0.y) + if dx > dy: + if dx > dz: return float(dx) + else: + if dy > dz: return float(dy) + return dz + +# http://zvold.blogspot.com/2010/01/bresenhams-line-drawing-algorithm-on_26.html +# http://zvold.blogspot.com/2010/02/line-of-sight-on-hexagonal-grid.html +# compute as an Array, the line of sight between 2 Tiles given by their col;row coordinates +# return the point after which the line of sight is blocked +func line_of_sight(p0 : Vector2, p1 : Vector2, tiles : Array) -> Vector2: + tiles.clear() + # orthogonal projection + var ox0 : float = p0.x - (p0.y + 1) / 2 + var ox1 : float = p1.x - (p1.y + 1) / 2 + var dy : int = int(p1.y) - int(p0.y) + var dx : float = ox1 - ox0 + # quadrant I && III + var q13 : bool = (dx >= 0 && dy >= 0) || (dx < 0 && dy < 0) + # is positive + var xs : int = 1 + var ys : int = 1 + if dx < 0: xs = -1 + if dy < 0: ys = -1 + # dx counts half width + dy = int(abs(dy)) + dx = abs(2 * dx) + var dx3 : int = int(3 * dx) + var dy3 : int = 3 * dy + # check for diagonals + if dx == 0 || dx == dy3: + return _diagonal_los(p0, p1, (dx == 0), q13, tiles) + # angle is less than 45° + var flat : bool = dx > dy3 + var x : int = int(p0.x) + var y : int = int(p0.y); + var e : int = int(-2 * dx) + var from : Tile = get_tile(p0) + var to : Tile = get_tile(p1) + var d : float = distance(p0, p1) + tiles.append(from) + from.blocked = false + var ret : Vector2 = Vector2(-1, -1) + var contact : bool = false + var los_blocked : bool = false + while (x != p1.x) or (y != p1.y): + if e > 0: + # quadrant I : up left + e -= (dy3 + dx3) + y += ys + if not q13: x -= xs + else: + e += dy3 + if (e > -dx) or (not flat && (e == -dx)): + # quadrant I : up right + e -= dx3 + y += ys + if q13: x += xs + elif e < -dx3: + # quadrant I : down right + e += dx3 + y -= ys + if not q13: x += xs + else: + # quadrant I : right + e += dy3 + x += xs + var q : Vector2 = Vector2(x, y) + var t : Tile = get_tile(q) + if los_blocked and not contact: + var prev : Tile = tiles[tiles.size() - 1] + var o : int = to_orientation(angle(prev, t)) + ret = _compute_contact(from.position, to.position, prev.position, o) + contact = true + tiles.append(t) + t.blocked = los_blocked + los_blocked = los_blocked or t.block_los(from, to, d, distance(p0, q)) + return ret + +func _diagonal_los(p0 : Vector2, p1 : Vector2, flat : bool, q13 : bool, tiles : Array) -> Vector2: + var dy : int = 1 if p1.y > p0.y else -1 + var dx : int = 1 if p1.x > p0.x else -1 + var x : int = int(p0.x) + var y : int = int(p0.y) + var from : Tile = get_tile(p0); + var to : Tile = get_tile(p1); + var d : float = distance(p0, p1) + tiles.append(from); + from.blocked = false; + var ret : Vector2 = Vector2(-1, -1) + var blocked : int = 0 + var contact : bool = false + var los_blocked : bool = false + while (x != p1.x) or (y != p1.y): + var idx : int = 4 + if flat: y += dy # up left + else: x += dx # right + var q : Vector2 = Vector2(x, y) + var t : Tile = get_tile(q) + if t.on_map: + tiles.append(t) + t.blocked = los_blocked + if t.block_los(from, to, d, distance(p0, q)): + blocked |= 0x01 + else: + blocked |= 0x01 + idx = 3 + + if flat: x += dx # up right + else: + y += dy # up right + if not q13: x -= dx + q = Vector2(x, y) + t = get_tile(q) + if t.on_map: + tiles.append(t) + t.blocked = los_blocked + if t.block_los(from, to, d, distance(p0, q)): + blocked |= 0x02 + else: + blocked |= 0x02 + idx = 3 + + if flat: y += dy # up + else: x += dx # diagonal + q = Vector2(x, y) + t = get_tile(q) + tiles.append(t) + t.blocked = los_blocked || blocked == 0x03 + if t.blocked and not contact: + var o : int = _compute_orientation(dx, dy, flat) + if not los_blocked and blocked == 0x03: + ret = _compute_contact(from.position, to.position, t.position, opposite(o)) + else: + ret = _compute_contact(from.position, to.position, tiles[tiles.size() - idx].position, o) + contact = true; + los_blocked = t.blocked || t.block_los(from, to, d, distance(p0, q)) + return ret + +func _compute_orientation(dx :int, dy :int, flat : bool) -> int: + if flat: + if v: return Orientation.S if dy == 1 else Orientation.N + else: return Orientation.S if dx == 1 else Orientation.N + if dx == 1: + if dy == 1: return Orientation.E + else: return Orientation.E if v else Orientation.N + else: + if dy == 1: return Orientation.W if v else Orientation.S + else: return Orientation.W + +func _compute_contact(from : Vector2, to : Vector2, t : Vector2, o : int) -> Vector2: + var dx : float = to.x - from.x + var dy : float = to.y - from.y + var n : float = float(IMAX) if dx == 0 else (dy / dx) + var c : float = from.y - (n * from.x) + if v: + if o == Orientation.N: return Vector2(t.x, t.y - s) + elif o == Orientation.S: return Vector2(t.x, t.y + s) + elif o == Orientation.E: + var x : float = t.x + dw + return Vector2(x, from.y + n * (x - from.x)) + elif o == Orientation.W: + var x : float = t.x - dw + return Vector2(x, from.y + n * (x - from.x)) + else: + var p : float = -m if (o == Orientation.SE or o == Orientation.NW) else m + var k : float = t.y - p * t.x + if o == Orientation.SE || o == Orientation.SW: k += s + else: k -= s + var x : float = (k - c) / (n - p) + return Vector2(x, n * x + c) + else: + if o == Orientation.E: return Vector2(t.x + s, t.y) + elif o == Orientation.W: return Vector2(t.x - s, t.y) + elif o == Orientation.N: + var y : float = t.y - dw + return Vector2(from.x + (y - from.y) / n, y) + elif o == Orientation.S: + var y : float = t.y + dw + return Vector2(from.x + (y - from.y) / n, y) + else: + var p : float = -im if (o == Orientation.SE or o == Orientation.NW) else +im + var k : float = 0 + if o == Orientation.SW or o == Orientation.NW: k = t.y - (p * (t.x - s)) + else: k = t.y - (p * (t.x + s)) + var x : float = (k - c) / (n - p) + return Vector2(x, n * x + c); + +# compute as an Array, the Tiles that can be reached by a given Piece from a Tile given by it's col;row coordinates +# return the size of the built Array +func possible_moves(piece : Piece, from : Tile, tiles : Array) -> int: + tiles.clear() + if piece.get_mp() <= 0 or not is_on_map(from.coords): return 0 + var road_march_bonus : int = piece.road_march_bonus() + search_count += 1 + from.parent = null + from.acc = piece.get_mp() + from.search_count = search_count + from.road_march = road_march_bonus > 0 + stack.push_back(from) + while(not stack.empty()): + var src : Tile = stack.pop_back() + if (src.acc + (road_march_bonus if src.road_march else 0)) <= 0: continue + # warning-ignore:return_value_discarded + _build_adjacents(src.coords) + for dst in adjacents: + if not dst.on_map: continue + var o : int = to_orientation(angle(src, dst)) + var cost : int = piece.move_cost(src, dst, o) + if (cost == -1): continue # impracticable + var r : int = src.acc - cost + var rm : bool = src.road_march and src.has_road(o) + # not enough MP even with RM, maybe first move allowed + if ((r + (road_march_bonus if rm else 0)) < 0 and not (src == from and piece.at_least_one_tile(dst))): continue + if dst.search_count != search_count: + dst.search_count = search_count + dst.acc = r + dst.parent = src + dst.road_march = rm + stack.push_back(dst) + tiles.append(dst) + elif (r > dst.acc or (rm and (r + road_march_bonus > dst.acc + (road_march_bonus if dst.road_march else 0)))): + dst.acc = r + dst.parent = src + dst.road_march = rm + stack.push_back(dst) + return tiles.size() + +# compute as an Array, the shortest path for a given Piece from a Tile to another given by there col;row coordinates +# return the size of the built Array +func shortest_path(piece : Piece, from : Tile, to : Tile, tiles : Array) -> int: + tiles.clear() + if from == to or not is_on_map(from.coords) or not is_on_map(to.coords): return tiles.size() + var road_march_bonus : int = piece.road_march_bonus() + search_count += 1 + from.acc = 0 + from.parent = null + from.search_count = search_count + from.road_march = road_march_bonus > 0 + stack.push_back(from) + while(not stack.empty()): + var src : Tile = stack.pop_back() + if (src == to): break + # warning-ignore:return_value_discarded + _build_adjacents(src.coords) + for dst in adjacents: + if not dst.on_map: continue + var o : int = to_orientation(angle(src, dst)) + var cost : int = piece.move_cost(src, dst, o) + if (cost == -1): continue # impracticable + cost += src.acc + var total : float = cost + distance(dst.coords, to.coords) + var rm : bool = src.road_march and src.has_road(o) + if rm: total -= road_march_bonus + var add : bool = false + if dst.search_count != search_count: + dst.search_count = search_count + add = true + elif dst.f > total or (rm and not dst.road_march and abs(dst.f - total) < 0.001): + stack.erase(dst) + add = true + if add: + dst.acc = cost + dst.f = total + dst.road_march = rm + dst.parent = src + var idx : int = IMAX + for k in range(stack.size()): + if stack[k].f <= dst.f: + idx = k + break + if idx == IMAX: stack.push_back(dst) + else: stack.insert(idx, dst) + stack.clear() + if to.search_count == search_count: + var t : Tile = to + while t != from: + tiles.push_front(t) + t = t.parent + tiles.push_front(from) + return tiles.size() + +func range_of_influence(piece : Piece, from : Tile, category : int, tiles : Array) -> int: + tiles.clear() + var max_range : int = piece.max_range_of_fire(category, from) + if not is_on_map(from.coords): return 0 + var tmp : Array = [] + search_count += 1 + from.search_count = search_count + stack.push_back(from) + while(not stack.empty()): + var src : Tile = stack.pop_back() + # warning-ignore:return_value_discarded + _build_adjacents(src.coords) + for dst in adjacents: + if not dst.on_map: continue + if dst.search_count == search_count: continue + dst.search_count = search_count + var d : int = int(distance(from.coords, dst.coords, false)) + if d > max_range: continue + if line_of_sight(from.coords, dst.coords, tmp).x != -1: continue + var o : int = distant_orientation(from, dst) + dst.f = piece.volume_of_fire(category, d, from, o, dst, distant_opposite(o)) + stack.push_back(dst) + tiles.append(dst) + return tiles.size() diff --git a/addons/hexgrid/HexMap.png b/addons/hexgrid/HexMap.png new file mode 100644 index 0000000..262d8c1 Binary files /dev/null and b/addons/hexgrid/HexMap.png differ diff --git a/addons/hexgrid/HexMap.png.import b/addons/hexgrid/HexMap.png.import new file mode 100644 index 0000000..c56b1da --- /dev/null +++ b/addons/hexgrid/HexMap.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/HexMap.png-86399ef085f54bb49aa45ad5daebe043.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/hexgrid/HexMap.png" +dest_files=[ "res://.import/HexMap.png-86399ef085f54bb49aa45ad5daebe043.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/addons/hexgrid/Piece.gd b/addons/hexgrid/Piece.gd new file mode 100644 index 0000000..e84208f --- /dev/null +++ b/addons/hexgrid/Piece.gd @@ -0,0 +1,35 @@ +#warning-ignore-all:unused_argument +extends Node2D + +class_name Piece, "res://addons/hexgrid/Piece.png" + +# movement points +func get_mp() -> int: + print("Piece#get_mp() must be overriden in a subclass") + return 0 + +# movement point bonus if you start your movement on a road and follow it +func road_march_bonus() -> int: + print("Piece#road_march_bonus() must be overriden in a subclass") + return 0 + +# movement cost from a Tile to another adjacent Tile +func move_cost(src : Tile, dst : Tile, orientation : int) -> int: + print("Piece#move_cost() must be overriden in a subclass") + return -1 # impracticable + +# are you allowed to move into that Tile as only move even if you don't have enough movement points +func at_least_one_tile(dst : Tile) -> bool: + print("Piece#at_least_one_tile() must be overriden in a subclass") + return true + +# the maximum range of fire with a given category of weapon +func max_range_of_fire(category : int, from : Tile) -> int: + print("Piece#max_range_of_fire() must be overriden in a subclass") + return 0 + +# the projected volume of fire with a given category of weapon at a given distance, +# out of a given Tile with a given orientation, into a given Tile with a given orientation +func volume_of_fire(category : int, distance : int, src : Tile, src_o : int, dst : Tile, dst_o : int) -> int: + print("Piece#volume_of_fire() must be overriden in a subclass") + return -1 # out of range diff --git a/addons/hexgrid/Piece.png b/addons/hexgrid/Piece.png new file mode 100644 index 0000000..a2cf111 Binary files /dev/null and b/addons/hexgrid/Piece.png differ diff --git a/addons/hexgrid/Piece.png.import b/addons/hexgrid/Piece.png.import new file mode 100644 index 0000000..ce53b80 --- /dev/null +++ b/addons/hexgrid/Piece.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Piece.png-5155cac4a0bf7c2a889be85d756a935e.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/hexgrid/Piece.png" +dest_files=[ "res://.import/Piece.png-5155cac4a0bf7c2a889be85d756a935e.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/addons/hexgrid/Tile.gd b/addons/hexgrid/Tile.gd new file mode 100644 index 0000000..b9463eb --- /dev/null +++ b/addons/hexgrid/Tile.gd @@ -0,0 +1,49 @@ +#warning-ignore-all:unused_argument +extends Node2D + +class_name Tile, "res://addons/hexgrid/Tile.png" + +var coords : Vector2 +var blocked : bool +var on_map : bool = false + +var acc : int +var f : float +var parent : Tile +var road_march : bool +var search_count : int + +func configure(p : Vector2, c: Vector2, o :Array) -> void: + position = p + coords = c + on_map = true + for t in o: + var s :Sprite = Sprite.new() + s.texture = load(t) + s.visible = false + add_child(s) + visible = false + +# is there a road with given orientation that drives out of that Tile +func has_road(orientation : int) -> bool: + print("Tile#has_road() must be overriden in a subclass") + return false + +# is the line of sight blocked from a Tile to another, d beeing the distance between from and to, +# dt beeing the distance between from and this Tile +func block_los(from : Tile, to : Tile, d : float, dt : float) -> bool: + print("Tile#block_los() must be overriden in a subclass") + return false + +func enable_overlay(i :int, v : bool) -> void: + get_child(i).visible = v + if v: visible = true + else : + visible = false + for o in get_children(): + if o.visible: + visible = true + break + +func is_overlay_on(i) -> bool: + return get_child(i).visible diff --git a/addons/hexgrid/Tile.png b/addons/hexgrid/Tile.png new file mode 100644 index 0000000..4d2f855 Binary files /dev/null and b/addons/hexgrid/Tile.png differ diff --git a/addons/hexgrid/Tile.png.import b/addons/hexgrid/Tile.png.import new file mode 100644 index 0000000..5c045cc --- /dev/null +++ b/addons/hexgrid/Tile.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Tile.png-c201d199cb1cc344924999eb46a6ca7d.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/hexgrid/Tile.png" +dest_files=[ "res://.import/Tile.png-c201d199cb1cc344924999eb46a6ca7d.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/assets/Anke.otf b/assets/Anke.otf deleted file mode 100644 index c577d63..0000000 Binary files a/assets/Anke.otf and /dev/null differ diff --git a/assets/black.png b/assets/black.png deleted file mode 100644 index 09a685d..0000000 Binary files a/assets/black.png and /dev/null differ diff --git a/assets/black.png.import b/assets/black.png.import deleted file mode 100644 index 02cbcd3..0000000 --- a/assets/black.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/black.png-0c928088330c4cddf9e28b960b6ccae3.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/black.png" -dest_files=[ "res://.import/black.png-0c928088330c4cddf9e28b960b6ccae3.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/block.png b/assets/block.png deleted file mode 100644 index 7704d65..0000000 Binary files a/assets/block.png and /dev/null differ diff --git a/assets/block.png.import b/assets/block.png.import deleted file mode 100644 index f050df8..0000000 --- a/assets/block.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/block.png-6b64ddb83a5b052a86170f1e6353c630.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/block.png" -dest_files=[ "res://.import/block.png-6b64ddb83a5b052a86170f1e6353c630.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/city.png b/assets/city.png deleted file mode 100644 index 35ef9a3..0000000 Binary files a/assets/city.png and /dev/null differ diff --git a/assets/city.png.import b/assets/city.png.import deleted file mode 100644 index e00f16f..0000000 --- a/assets/city.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/city.png-02b383d5b5b6aa591b88e70ba700cd66.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/city.png" -dest_files=[ "res://.import/city.png-02b383d5b5b6aa591b88e70ba700cd66.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/green.png b/assets/green.png deleted file mode 100644 index 6970efc..0000000 Binary files a/assets/green.png and /dev/null differ diff --git a/assets/green.png.import b/assets/green.png.import deleted file mode 100644 index dbe261a..0000000 --- a/assets/green.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/green.png-23da064ef749b17ee836f545d262d73c.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/green.png" -dest_files=[ "res://.import/green.png-23da064ef749b17ee836f545d262d73c.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/map-h.png b/assets/map-h.png deleted file mode 100644 index 732ef4a..0000000 Binary files a/assets/map-h.png and /dev/null differ diff --git a/assets/map-h.png.import b/assets/map-h.png.import deleted file mode 100644 index c21fd86..0000000 --- a/assets/map-h.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/map-h.png-8265185c00d0ece6b3d5aec651507180.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/map-h.png" -dest_files=[ "res://.import/map-h.png-8265185c00d0ece6b3d5aec651507180.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/map-v.png b/assets/map-v.png deleted file mode 100644 index 3960ffc..0000000 Binary files a/assets/map-v.png and /dev/null differ diff --git a/assets/map-v.png.import b/assets/map-v.png.import deleted file mode 100644 index cc39beb..0000000 --- a/assets/map-v.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/map-v.png-6762f953af17151852d4fd98e4f77f87.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/map-v.png" -dest_files=[ "res://.import/map-v.png-6762f953af17151852d4fd98e4f77f87.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/mountain.png b/assets/mountain.png deleted file mode 100644 index ebc224b..0000000 Binary files a/assets/mountain.png and /dev/null differ diff --git a/assets/mountain.png.import b/assets/mountain.png.import deleted file mode 100644 index 56665ef..0000000 --- a/assets/mountain.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/mountain.png-b2add8ed35f94e98573ad9ba99ceec37.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/mountain.png" -dest_files=[ "res://.import/mountain.png-b2add8ed35f94e98573ad9ba99ceec37.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/move.png b/assets/move.png deleted file mode 100644 index 01db48d..0000000 Binary files a/assets/move.png and /dev/null differ diff --git a/assets/move.png.import b/assets/move.png.import deleted file mode 100644 index 2b51d5e..0000000 --- a/assets/move.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/move.png-33f8bcb686112ff50a89f38cea6406cb.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/move.png" -dest_files=[ "res://.import/move.png-33f8bcb686112ff50a89f38cea6406cb.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/red.png b/assets/red.png deleted file mode 100644 index 0bf4075..0000000 Binary files a/assets/red.png and /dev/null differ diff --git a/assets/red.png.import b/assets/red.png.import deleted file mode 100644 index 8ae5fee..0000000 --- a/assets/red.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/red.png-d5f39e261e8585dfbc0a32aa9fd1a167.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/red.png" -dest_files=[ "res://.import/red.png-d5f39e261e8585dfbc0a32aa9fd1a167.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/short.png b/assets/short.png deleted file mode 100644 index cb91627..0000000 Binary files a/assets/short.png and /dev/null differ diff --git a/assets/short.png.import b/assets/short.png.import deleted file mode 100644 index 55af806..0000000 --- a/assets/short.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/short.png-6337ed76204123df33053be0499ad3de.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/short.png" -dest_files=[ "res://.import/short.png-6337ed76204123df33053be0499ad3de.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/tank.png b/assets/tank.png deleted file mode 100644 index 949ef59..0000000 Binary files a/assets/tank.png and /dev/null differ diff --git a/assets/tank.png.import b/assets/tank.png.import deleted file mode 100644 index 249a86a..0000000 --- a/assets/tank.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/tank.png-44e29c25b935427e1d3fe5ee8f405436.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/tank.png" -dest_files=[ "res://.import/tank.png-44e29c25b935427e1d3fe5ee8f405436.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/target.png b/assets/target.png deleted file mode 100644 index 997df02..0000000 Binary files a/assets/target.png and /dev/null differ diff --git a/assets/target.png.import b/assets/target.png.import deleted file mode 100644 index 3636021..0000000 --- a/assets/target.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/target.png-52c019dda84da6fc854650719104c4ec.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/target.png" -dest_files=[ "res://.import/target.png-52c019dda84da6fc854650719104c4ec.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/assets/tree.png b/assets/tree.png deleted file mode 100644 index b3300a4..0000000 Binary files a/assets/tree.png and /dev/null differ diff --git a/assets/tree.png.import b/assets/tree.png.import deleted file mode 100644 index cd0af4c..0000000 --- a/assets/tree.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/tree.png-bf64094b89302dd1be83aa5edf9988ef.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/tree.png" -dest_files=[ "res://.import/tree.png-bf64094b89302dd1be83aa5edf9988ef.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/demo/Hex.gd b/demo/Hex.gd index 99bdbd2..029f6c3 100644 --- a/demo/Hex.gd +++ b/demo/Hex.gd @@ -1,7 +1,7 @@ #warning-ignore-all:unused_argument extends Tile -class_name Hex, "res://godot/Tile.png" +class_name Hex, "res://addons/hexgrid/Tile.png" var type : int = -1 var roads : int = 0 diff --git a/demo/Main.tscn b/demo/Main.tscn index 6fa7f31..6ac653f 100644 --- a/demo/Main.tscn +++ b/demo/Main.tscn @@ -1,11 +1,11 @@ [gd_scene load_steps=10 format=2] [ext_resource path="res://demo/Camera.gd" type="Script" id=1] -[ext_resource path="res://assets/Anke.otf" type="DynamicFontData" id=2] -[ext_resource path="res://assets/target.png" type="Texture" id=3] +[ext_resource path="res://demo/assets/Anke.otf" type="DynamicFontData" id=2] +[ext_resource path="res://demo/assets/target.png" type="Texture" id=3] [ext_resource path="res://demo/Map.gd" type="Script" id=4] [ext_resource path="res://demo/Los.gd" type="Script" id=5] -[ext_resource path="res://assets/tank.png" type="Texture" id=6] +[ext_resource path="res://demo/assets/tank.png" type="Texture" id=6] [ext_resource path="res://demo/Main.gd" type="Script" id=7] [sub_resource type="DynamicFont" id=1] diff --git a/demo/Map.gd b/demo/Map.gd index 22ad0fd..abfc231 100644 --- a/demo/Map.gd +++ b/demo/Map.gd @@ -2,17 +2,17 @@ extends Sprite signal hex_touched(pos, hex, key) -const MAPH : String = "res://assets/map-h.png" -const MAPV : String = "res://assets/map-v.png" -const BLOCK : String = "res://assets/block.png" -const BLACK : String = "res://assets/black.png" -const MOVE : String = "res://assets/move.png" -const SHORT : String = "res://assets/short.png" -const RED : String = "res://assets/red.png" -const GREEN : String = "res://assets/green.png" -const TREE : String = "res://assets/tree.png" -const CITY : String = "res://assets/city.png" -const MOUNT : String = "res://assets/mountain.png" +const MAPH : String = "res://demo/assets/map-h.png" +const MAPV : String = "res://demo/assets/map-v.png" +const BLOCK : String = "res://demo/assets/block.png" +const BLACK : String = "res://demo/assets/black.png" +const MOVE : String = "res://demo/assets/move.png" +const SHORT : String = "res://demo/assets/short.png" +const RED : String = "res://demo/assets/red.png" +const GREEN : String = "res://demo/assets/green.png" +const TREE : String = "res://demo/assets/tree.png" +const CITY : String = "res://demo/assets/city.png" +const MOUNT : String = "res://demo/assets/mountain.png" var drag : Sprite diff --git a/demo/Unit.gd b/demo/Unit.gd index 0b67053..e18ebff 100644 --- a/demo/Unit.gd +++ b/demo/Unit.gd @@ -1,7 +1,7 @@ #warning-ignore-all:unused_argument extends Piece -class_name Unit, "res://godot/Piece.png" +class_name Unit, "res://addons/hexgrid/Piece.png" func get_mp() -> int: return 2 diff --git a/demo/assets/Anke.otf b/demo/assets/Anke.otf new file mode 100644 index 0000000..c577d63 Binary files /dev/null and b/demo/assets/Anke.otf differ diff --git a/demo/assets/black.png b/demo/assets/black.png new file mode 100644 index 0000000..09a685d Binary files /dev/null and b/demo/assets/black.png differ diff --git a/demo/assets/black.png.import b/demo/assets/black.png.import new file mode 100644 index 0000000..c4ccf4e --- /dev/null +++ b/demo/assets/black.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/black.png-e51bb9446ed3e9a231bbefdd5d845a61.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/black.png" +dest_files=[ "res://.import/black.png-e51bb9446ed3e9a231bbefdd5d845a61.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/block.png b/demo/assets/block.png new file mode 100644 index 0000000..7704d65 Binary files /dev/null and b/demo/assets/block.png differ diff --git a/demo/assets/block.png.import b/demo/assets/block.png.import new file mode 100644 index 0000000..d93d59d --- /dev/null +++ b/demo/assets/block.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/block.png-7b666470ec7d1ed55123323983805a34.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/block.png" +dest_files=[ "res://.import/block.png-7b666470ec7d1ed55123323983805a34.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/city.png b/demo/assets/city.png new file mode 100644 index 0000000..35ef9a3 Binary files /dev/null and b/demo/assets/city.png differ diff --git a/demo/assets/city.png.import b/demo/assets/city.png.import new file mode 100644 index 0000000..8175df8 --- /dev/null +++ b/demo/assets/city.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/city.png-b5e144e6bc7635251820830d2b6c5a50.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/city.png" +dest_files=[ "res://.import/city.png-b5e144e6bc7635251820830d2b6c5a50.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/green.png b/demo/assets/green.png new file mode 100644 index 0000000..6970efc Binary files /dev/null and b/demo/assets/green.png differ diff --git a/demo/assets/green.png.import b/demo/assets/green.png.import new file mode 100644 index 0000000..fad21c4 --- /dev/null +++ b/demo/assets/green.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/green.png-6cabcf440c4bebeca5e9f1949a914b94.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/green.png" +dest_files=[ "res://.import/green.png-6cabcf440c4bebeca5e9f1949a914b94.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/map-h.png b/demo/assets/map-h.png new file mode 100644 index 0000000..732ef4a Binary files /dev/null and b/demo/assets/map-h.png differ diff --git a/demo/assets/map-h.png.import b/demo/assets/map-h.png.import new file mode 100644 index 0000000..7fd3434 --- /dev/null +++ b/demo/assets/map-h.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/map-h.png-a625f2c7dc4113b3d54e67ecad578faa.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/map-h.png" +dest_files=[ "res://.import/map-h.png-a625f2c7dc4113b3d54e67ecad578faa.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/map-v.png b/demo/assets/map-v.png new file mode 100644 index 0000000..3960ffc Binary files /dev/null and b/demo/assets/map-v.png differ diff --git a/demo/assets/map-v.png.import b/demo/assets/map-v.png.import new file mode 100644 index 0000000..3c082e1 --- /dev/null +++ b/demo/assets/map-v.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/map-v.png-f23934658a4a2f9eda7b09606fcff75d.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/map-v.png" +dest_files=[ "res://.import/map-v.png-f23934658a4a2f9eda7b09606fcff75d.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/mountain.png b/demo/assets/mountain.png new file mode 100644 index 0000000..ebc224b Binary files /dev/null and b/demo/assets/mountain.png differ diff --git a/demo/assets/mountain.png.import b/demo/assets/mountain.png.import new file mode 100644 index 0000000..1678f9b --- /dev/null +++ b/demo/assets/mountain.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/mountain.png-2ae0c60bcbdbe0b637e25f7b00914834.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/mountain.png" +dest_files=[ "res://.import/mountain.png-2ae0c60bcbdbe0b637e25f7b00914834.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/move.png b/demo/assets/move.png new file mode 100644 index 0000000..01db48d Binary files /dev/null and b/demo/assets/move.png differ diff --git a/demo/assets/move.png.import b/demo/assets/move.png.import new file mode 100644 index 0000000..94b7afa --- /dev/null +++ b/demo/assets/move.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/move.png-cbedb7692b73fcaf2a6f182fb2ab302a.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/move.png" +dest_files=[ "res://.import/move.png-cbedb7692b73fcaf2a6f182fb2ab302a.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/red.png b/demo/assets/red.png new file mode 100644 index 0000000..0bf4075 Binary files /dev/null and b/demo/assets/red.png differ diff --git a/demo/assets/red.png.import b/demo/assets/red.png.import new file mode 100644 index 0000000..9a47dff --- /dev/null +++ b/demo/assets/red.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/red.png-0fb5b28e6c289aea54776e2a268c9918.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/red.png" +dest_files=[ "res://.import/red.png-0fb5b28e6c289aea54776e2a268c9918.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/short.png b/demo/assets/short.png new file mode 100644 index 0000000..cb91627 Binary files /dev/null and b/demo/assets/short.png differ diff --git a/demo/assets/short.png.import b/demo/assets/short.png.import new file mode 100644 index 0000000..a73f3dd --- /dev/null +++ b/demo/assets/short.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/short.png-91db7f36df1a087629b942a028fb5df2.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/short.png" +dest_files=[ "res://.import/short.png-91db7f36df1a087629b942a028fb5df2.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/tank.png b/demo/assets/tank.png new file mode 100644 index 0000000..949ef59 Binary files /dev/null and b/demo/assets/tank.png differ diff --git a/demo/assets/tank.png.import b/demo/assets/tank.png.import new file mode 100644 index 0000000..26613fc --- /dev/null +++ b/demo/assets/tank.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/tank.png-2f13e859efcf4e73b133475e609ef36b.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/tank.png" +dest_files=[ "res://.import/tank.png-2f13e859efcf4e73b133475e609ef36b.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/target.png b/demo/assets/target.png new file mode 100644 index 0000000..997df02 Binary files /dev/null and b/demo/assets/target.png differ diff --git a/demo/assets/target.png.import b/demo/assets/target.png.import new file mode 100644 index 0000000..81d6ccc --- /dev/null +++ b/demo/assets/target.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/target.png-c45d87ea7b33e72c20871629efe7753d.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/target.png" +dest_files=[ "res://.import/target.png-c45d87ea7b33e72c20871629efe7753d.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/demo/assets/tree.png b/demo/assets/tree.png new file mode 100644 index 0000000..b3300a4 Binary files /dev/null and b/demo/assets/tree.png differ diff --git a/demo/assets/tree.png.import b/demo/assets/tree.png.import new file mode 100644 index 0000000..4b2123d --- /dev/null +++ b/demo/assets/tree.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/tree.png-09a81eaacb2ae7a9e3156ec7110e0c2e.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://demo/assets/tree.png" +dest_files=[ "res://.import/tree.png-09a81eaacb2ae7a9e3156ec7110e0c2e.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/godot/HexMap.png b/godot/HexMap.png deleted file mode 100644 index 262d8c1..0000000 Binary files a/godot/HexMap.png and /dev/null differ diff --git a/godot/HexMap.png.import b/godot/HexMap.png.import deleted file mode 100644 index e420f52..0000000 --- a/godot/HexMap.png.import +++ /dev/null @@ -1,35 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/HexMap.png-021fe668dbb17ad9c306310ffe1cd0f0.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://godot/HexMap.png" -dest_files=[ "res://.import/HexMap.png-021fe668dbb17ad9c306310ffe1cd0f0.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -process/normal_map_invert_y=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/godot/Piece.png b/godot/Piece.png deleted file mode 100644 index a2cf111..0000000 Binary files a/godot/Piece.png and /dev/null differ diff --git a/godot/Piece.png.import b/godot/Piece.png.import deleted file mode 100644 index 74910d6..0000000 --- a/godot/Piece.png.import +++ /dev/null @@ -1,35 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/Piece.png-0617c788b12591c5bfc6b47da73ecbe2.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://godot/Piece.png" -dest_files=[ "res://.import/Piece.png-0617c788b12591c5bfc6b47da73ecbe2.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -process/normal_map_invert_y=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/godot/Tile.png b/godot/Tile.png deleted file mode 100644 index 4d2f855..0000000 Binary files a/godot/Tile.png and /dev/null differ diff --git a/godot/Tile.png.import b/godot/Tile.png.import deleted file mode 100644 index beabdc8..0000000 --- a/godot/Tile.png.import +++ /dev/null @@ -1,35 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/Tile.png-4e4b98625182aa9b1a6a23fb8ef3a29d.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://godot/Tile.png" -dest_files=[ "res://.import/Tile.png-4e4b98625182aa9b1a6a23fb8ef3a29d.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -process/normal_map_invert_y=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/project.godot b/project.godot index 1846513..e89d9c0 100644 --- a/project.godot +++ b/project.godot @@ -17,17 +17,17 @@ _global_script_classes=[ { "base": "Node", "class": "HexBoard", "language": "GDScript", -"path": "res://HexMap.gd" +"path": "res://addons/hexgrid/HexMap.gd" }, { "base": "Node2D", "class": "Piece", "language": "GDScript", -"path": "res://Piece.gd" +"path": "res://addons/hexgrid/Piece.gd" }, { "base": "Node2D", "class": "Tile", "language": "GDScript", -"path": "res://Tile.gd" +"path": "res://addons/hexgrid/Tile.gd" }, { "base": "Piece", "class": "Unit", @@ -35,11 +35,11 @@ _global_script_classes=[ { "path": "res://demo/Unit.gd" } ] _global_script_class_icons={ -"Hex": "res://godot/Tile.png", -"HexBoard": "res://godot/HexMap.png", -"Piece": "res://godot/Piece.png", -"Tile": "res://godot/Tile.png", -"Unit": "res://godot/Piece.png" +"Hex": "res://addons/hexgrid/Tile.png", +"HexBoard": "", +"Piece": "", +"Tile": "", +"Unit": "res://addons/hexgrid/Piece.png" } [application] -- cgit v1.1-2-g2b99