Linting
This commit is contained in:
parent
1ff2e26cd4
commit
5c95bf11e7
|
@ -2,6 +2,7 @@ from dungeonbattle.game import Game
|
|||
from dungeonbattle.display.display_manager import DisplayManager
|
||||
from dungeonbattle.term_manager import TermManager
|
||||
|
||||
|
||||
class Bootstrap:
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
import curses
|
||||
from typing import Any, Union
|
||||
|
||||
from typing import Any
|
||||
from dungeonbattle.tests.screen import FakePad
|
||||
|
||||
|
||||
class Display:
|
||||
x: int
|
||||
y: int
|
||||
width: int
|
||||
height: int
|
||||
|
||||
def __init__(self, screen: Any, pack: Any):
|
||||
self.screen = screen
|
||||
self.pack = pack
|
||||
|
@ -13,19 +17,19 @@ class Display:
|
|||
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
|
||||
return curses.newpad(height, width) if self.screen else FakePad()
|
||||
|
||||
def resize(self, y, x, height, width):
|
||||
def resize(self, y: int, x: int, height: int, width: int) -> None:
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.width = width
|
||||
self.height = height
|
||||
|
||||
def refresh(self, *args):
|
||||
def refresh(self, *args) -> None:
|
||||
if len(args) == 4:
|
||||
self.resize(*args)
|
||||
self.display()
|
||||
|
||||
def display(self):
|
||||
pass
|
||||
def display(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def rows(self) -> int:
|
||||
|
|
|
@ -15,11 +15,13 @@ class DisplayManager:
|
|||
pack = TexturePack.get_pack(self.game.settings.TEXTURE_PACK)
|
||||
self.mapdisplay = MapDisplay(screen, pack)
|
||||
self.statsdisplay = StatsDisplay(screen, pack)
|
||||
self.mainmenudisplay = MainMenuDisplay(self.game.main_menu, screen, pack)
|
||||
self.displays = [self.statsdisplay, self.mapdisplay, self.mainmenudisplay]
|
||||
self.mainmenudisplay = MainMenuDisplay(self.game.main_menu,
|
||||
screen, pack)
|
||||
self.displays = [self.statsdisplay, self.mapdisplay,
|
||||
self.mainmenudisplay]
|
||||
self.update_game_components()
|
||||
|
||||
def update_game_components(self):
|
||||
def update_game_components(self) -> None:
|
||||
for d in self.displays:
|
||||
d.pack = TexturePack.get_pack(self.game.settings.TEXTURE_PACK)
|
||||
self.mapdisplay.update_map(self.game.map)
|
||||
|
@ -28,12 +30,11 @@ class DisplayManager:
|
|||
def refresh(self) -> None:
|
||||
if self.game.state == GameMode.PLAY:
|
||||
self.mapdisplay.refresh(0, 0, self.rows * 4 // 5, self.cols)
|
||||
self.statsdisplay.refresh(self.rows*4//5, 0, self.rows//5, self.cols)
|
||||
self.statsdisplay.refresh(self.rows * 4 // 5, 0,
|
||||
self.rows // 5, self.cols)
|
||||
if self.game.state == GameMode.MAINMENU:
|
||||
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
|
||||
|
||||
# self.menudisplay.refresh(self.position)
|
||||
|
||||
def ensure_resized(self, *pads) -> bool:
|
||||
"""
|
||||
If the window got resized, ensure that the pads are also resized.
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
from typing import Any
|
||||
import curses
|
||||
|
||||
from dungeonbattle.display.texturepack import TexturePack
|
||||
from dungeonbattle.entities.player import Player
|
||||
from dungeonbattle.interfaces import Map
|
||||
from .display import Display
|
||||
|
||||
|
||||
class MapDisplay(Display):
|
||||
player: Player
|
||||
|
||||
def __init__(self, *args):
|
||||
super().__init__(*args)
|
||||
|
||||
def update_map(self, m: Map):
|
||||
def update_map(self, m: Map) -> None:
|
||||
self.map = m
|
||||
self.pad = curses.newpad(m.height, m.width + 1)
|
||||
self.pad = self.newpad(m.height, m.width + 1)
|
||||
|
||||
def update_pad(self) -> None:
|
||||
self.pad.addstr(0, 0, self.map.draw_string(self.pack))
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from dungeonbattle.menus import Menu, MainMenu
|
||||
from typing import Any
|
||||
from .display import Display
|
||||
import curses
|
||||
|
||||
|
||||
class MenuDisplay(Display):
|
||||
position: int
|
||||
|
@ -10,7 +9,7 @@ class MenuDisplay(Display):
|
|||
super().__init__(*args)
|
||||
self.menubox = self.newpad(self.rows, self.cols)
|
||||
|
||||
def update_menu(self, menu: Menu):
|
||||
def update_menu(self, menu: Menu) -> None:
|
||||
self.menu = menu
|
||||
self.values = [str(a) for a in menu.values]
|
||||
self.trueheight = len(self.values)
|
||||
|
@ -21,11 +20,11 @@ class MenuDisplay(Display):
|
|||
for i in range(self.trueheight):
|
||||
self.pad.addstr(i, 0, " " + self.values[i])
|
||||
|
||||
|
||||
def update_pad(self) -> None:
|
||||
for i in range(self.trueheight):
|
||||
self.pad.addstr(i, 0, " ")
|
||||
self.pad.addstr(self.menu.position,0,">") #set a marker on the selected line
|
||||
# set a marker on the selected line
|
||||
self.pad.addstr(self.menu.position, 0, ">")
|
||||
|
||||
def display(self) -> None:
|
||||
if self.height - 2 >= self.menu.position - 1:
|
||||
|
@ -33,12 +32,12 @@ class MenuDisplay(Display):
|
|||
elif self.height - 2 >= self.trueheight - self.menu.position:
|
||||
cornery = self.trueheight - self.height + 2
|
||||
|
||||
|
||||
# Menu box
|
||||
self.menubox.addstr(0, 0, "┏" + "━" * (self.width - 2) + "┓")
|
||||
for i in range(1, self.height - 1):
|
||||
self.menubox.addstr(i, 0, "┃" + " " * (self.width - 2) + "┃")
|
||||
self.menubox.addstr(self.height-1, 0, "┗"+"━"*(self.width-2)+"┛")
|
||||
self.menubox.addstr(self.height - 1, 0,
|
||||
"┗" + "━" * (self.width - 2) + "┛")
|
||||
|
||||
self.menubox.refresh(0, 0, self.y, self.x,
|
||||
self.height + self.y,
|
||||
|
@ -56,6 +55,7 @@ class MenuDisplay(Display):
|
|||
def preferred_height(self) -> int:
|
||||
return self.trueheight + 2
|
||||
|
||||
|
||||
class MainMenuDisplay(Display):
|
||||
def __init__(self, menu: MainMenu, *args):
|
||||
super().__init__(*args)
|
||||
|
@ -70,10 +70,11 @@ class MainMenuDisplay(Display):
|
|||
|
||||
def display(self) -> None:
|
||||
for i in range(len(self.title)):
|
||||
self.pad.addstr(4+i,self.width//2-len(self.title[0])//2-1,self.title[i])
|
||||
self.pad.addstr(4 + i, self.width // 2
|
||||
- len(self.title[0]) // 2 - 1, self.title[i])
|
||||
self.pad.refresh(0, 0, self.y, self.x, self.height, self.width)
|
||||
menuwidth = min(self.menudisplay.preferred_width, self.width)
|
||||
menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1
|
||||
self.menudisplay.refresh(menuy, menux, min(self.menudisplay.preferred_height, self.height-menuy), menuwidth)
|
||||
|
||||
|
||||
self.menudisplay.refresh(
|
||||
menuy, menux, min(self.menudisplay.preferred_height,
|
||||
self.height - menuy), menuwidth)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
from typing import Any
|
||||
from .display import Display
|
||||
import curses
|
||||
|
||||
from dungeonbattle.entities.player import Player
|
||||
|
||||
|
@ -12,7 +10,7 @@ class StatsDisplay(Display):
|
|||
super().__init__(*args)
|
||||
self.pad = self.newpad(self.rows, self.cols)
|
||||
|
||||
def update_player(self, p: Player):
|
||||
def update_player(self, p: Player) -> None:
|
||||
self.player = p
|
||||
|
||||
def update_pad(self) -> None:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import sys
|
||||
from typing import Any
|
||||
|
||||
from .display.display import Display
|
||||
from .entities.player import Player
|
||||
from .interfaces import Map
|
||||
from .settings import Settings
|
||||
|
|
Loading…
Reference in New Issue