Linting
This commit is contained in:
parent
01cdea6edc
commit
9df1ac7883
|
@ -2,7 +2,6 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from json import JSONDecodeError
|
||||
from random import randint
|
||||
from typing import Any, Optional, List
|
||||
import curses
|
||||
import json
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
from enum import Enum, auto
|
||||
from math import ceil, sqrt
|
||||
from itertools import product
|
||||
from random import choice, choices, randint
|
||||
from random import choice, randint
|
||||
from typing import List, Optional, Any, Dict, Tuple
|
||||
from queue import PriorityQueue
|
||||
from functools import reduce
|
||||
|
|
|
@ -26,8 +26,9 @@ DEFAULT_PARAMS = {
|
|||
"spawn_per_region": [1, 2],
|
||||
}
|
||||
|
||||
def dist(level, y1, x1, y2, x2):
|
||||
copy = [[t for t in l] for l in level]
|
||||
|
||||
def dist(level: List[List[Tile]], y1: int, x1: int, y2: int, x2: int) -> int:
|
||||
copy = [[t for t in row] for row in level]
|
||||
dist = -1
|
||||
queue, next_queue = [[y1, x1]], [0]
|
||||
while next_queue:
|
||||
|
@ -44,6 +45,7 @@ def dist(level, y1, x1, y2, x2):
|
|||
queue = next_queue
|
||||
return -1
|
||||
|
||||
|
||||
class Generator:
|
||||
def __init__(self, params: dict = None):
|
||||
self.params = params or DEFAULT_PARAMS
|
||||
|
@ -89,7 +91,7 @@ class Generator:
|
|||
level[y - door_y + ry][x - door_x + rx] = Tile.FLOOR
|
||||
|
||||
@staticmethod
|
||||
def add_loop(level: List[List[Tile]], y: int, x: int) -> None:
|
||||
def add_loop(level: List[List[Tile]], y: int, x: int) -> bool:
|
||||
h, w = len(level), len(level[0])
|
||||
if level[y][x] != Tile.EMPTY:
|
||||
return False
|
||||
|
@ -106,11 +108,14 @@ class Generator:
|
|||
|
||||
# if adding the path would make the two tiles significantly closer
|
||||
# and its sides don't touch already placed terrain, build it
|
||||
def verify_sides():
|
||||
for Dx, Dy in [[dy, dx], [-dy, -dx]]:
|
||||
def verify_sides() -> bool:
|
||||
for delta_x, delta_y in [[dy, dx], [-dy, -dx]]:
|
||||
for i in range(1, y2 - y1 + x2 - x1):
|
||||
if not(0<= y1+Dy+i*dy < h and 0 <= x1+Dx+i*dx < w) or \
|
||||
level[y1+Dy+i*dy][x1+Dx+i*dx].can_walk():
|
||||
if not (0 <= y1 + delta_y + i * dy < h
|
||||
and 0 <= x1 + delta_x + i * dx < w) or \
|
||||
level[y1 + delta_y + i * dy][x1 + delta_x
|
||||
+ i * dx]\
|
||||
.can_walk():
|
||||
return False
|
||||
return True
|
||||
if dist(level, y1, x1, y2, x2) < 20 and verify_sides():
|
||||
|
@ -143,7 +148,8 @@ class Generator:
|
|||
return 0, 0, 0, 0
|
||||
|
||||
@staticmethod
|
||||
def build_door(room, y, x, dy, dx, length):
|
||||
def build_door(room: List[List[Tile]], y: int, x: int,
|
||||
dy: int, dx: int, length: int) -> bool:
|
||||
rh, rw = len(room), len(room[0])
|
||||
# verify we are pointing away from a floor tile
|
||||
if not(0 <= y - dy < rh and 0 <= x - dx < rw) \
|
||||
|
@ -228,7 +234,7 @@ class Generator:
|
|||
-> Tuple[List[list], int, int, int, int]:
|
||||
return self.create_circular_room()
|
||||
|
||||
def register_spawn_area(self, area:List[List[Tile]]):
|
||||
def register_spawn_area(self, area: List[List[Tile]]) -> None:
|
||||
spawn_positions = []
|
||||
for y, line in enumerate(area):
|
||||
for x, tile in enumerate(line):
|
||||
|
@ -236,13 +242,13 @@ class Generator:
|
|||
spawn_positions.append([y, x])
|
||||
self.queued_area = spawn_positions
|
||||
|
||||
def update_spawnable(self, y, x):
|
||||
if self.queued_area != None:
|
||||
def update_spawnable(self, y: int, x: int) -> None:
|
||||
if self.queued_area is not None:
|
||||
translated_area = [[y + ry, x + rx] for ry, rx in self.queued_area]
|
||||
self.spawn_areas.append(translated_area)
|
||||
self.queued_area = None
|
||||
|
||||
def populate(self, rv):
|
||||
def populate(self, rv: Map) -> None:
|
||||
min_c, max_c = self.params["spawn_per_region"]
|
||||
for region in self.spawn_areas:
|
||||
entity_count = randint(min_c, max_c)
|
||||
|
|
|
@ -16,7 +16,7 @@ class TestBroguelike(unittest.TestCase):
|
|||
self.stom = lambda x: Map.load_from_string("0 0\n" + x)
|
||||
self.mtos = lambda x: x.draw_string(TexturePack.ASCII_PACK)
|
||||
|
||||
def test_dist(self):
|
||||
def test_dist(self) -> None:
|
||||
m = self.stom(".. ..\n ... ")
|
||||
distance = broguelike.dist(m.tiles, 0, 0, 0, 4)
|
||||
self.assertEqual(distance, 6)
|
||||
|
@ -37,7 +37,7 @@ class TestBroguelike(unittest.TestCase):
|
|||
queue += Map.neighbourhood(grid, y, x)
|
||||
return not any([t.can_walk() for row in grid for t in row])
|
||||
|
||||
def test_build_doors(self):
|
||||
def test_build_doors(self) -> None:
|
||||
m = self.stom(". .\n. .\n. .\n")
|
||||
self.assertFalse(self.generator.build_door(m.tiles, 1, 1, 0, 1, 2))
|
||||
|
||||
|
@ -53,4 +53,3 @@ class TestBroguelike(unittest.TestCase):
|
|||
self.assertFalse(self.generator.add_loop(m.tiles, 0, 0))
|
||||
m = self.stom("...\n. .\n...")
|
||||
self.assertFalse(self.generator.add_loop(m.tiles, 1, 1))
|
||||
|
||||
|
|
Loading…
Reference in New Issue