77
88import copy
99import math
10- import os
1110import random
1211import sys
1312import time
1413import warnings
15- from typing import Any , List
14+ from pathlib import Path
15+ from typing import Any
1616
1717import numpy as np
1818from numpy .typing import NDArray
2121import tcod .render
2222import tcod .sdl .render
2323
24+ # ruff: noqa: S311
25+
2426if not sys .warnoptions :
2527 warnings .simplefilter ("default" ) # Show all warnings.
2628
29+ DATA_DIR = Path (__file__ ).parent / "../libtcod/data"
30+ """Path of the samples data directory."""
2731
28- def get_data (path : str ) -> str :
29- """Return the path to a resource in the libtcod data directory,"""
30- SCRIPT_DIR = os .path .dirname (__file__ )
31- DATA_DIR = os .path .join (SCRIPT_DIR , "../libtcod/data" )
32- assert os .path .exists (DATA_DIR ), (
33- "Data directory is missing," " did you forget to run `git submodule update --init`?"
34- )
35- return os .path .join (DATA_DIR , path )
36-
32+ assert DATA_DIR .exists (), "Data directory is missing, did you forget to run `git submodule update --init`?"
3733
3834WHITE = (255 , 255 , 255 )
3935GREY = (127 , 127 , 127 )
@@ -45,7 +41,7 @@ def get_data(path: str) -> str:
4541SAMPLE_SCREEN_HEIGHT = 20
4642SAMPLE_SCREEN_X = 20
4743SAMPLE_SCREEN_Y = 10
48- FONT = get_data ( "fonts/dejavu10x10_gs_tc.png" )
44+ FONT = DATA_DIR / "fonts/dejavu10x10_gs_tc.png"
4945
5046# Mutable global names.
5147context : tcod .context .Context
@@ -564,10 +560,9 @@ def draw_ui(self) -> None:
564560 1 ,
565561 1 ,
566562 "IJKL : move around\n "
567- "T : torch fx %s\n "
568- "W : light walls %s\n "
569- "+-: algo %s"
570- % (
563+ "T : torch fx {}\n "
564+ "W : light walls {}\n "
565+ "+-: algo {}" .format (
571566 "on " if self .torch else "off" ,
572567 "on " if self .light_walls else "off" ,
573568 FOV_ALGO_NAMES [self .algo_num ],
@@ -1032,9 +1027,9 @@ class ImageSample(Sample):
10321027 def __init__ (self ) -> None :
10331028 self .name = "Image toolkit"
10341029
1035- self .img = tcod .image_load (get_data ( "img/skull.png" ) )
1030+ self .img = tcod .image_load (DATA_DIR / "img/skull.png" )
10361031 self .img .set_key_color (BLACK )
1037- self .circle = tcod .image_load (get_data ( "img/circle.png" ) )
1032+ self .circle = tcod .image_load (DATA_DIR / "img/circle.png" )
10381033
10391034 def on_draw (self ) -> None :
10401035 sample_console .clear ()
@@ -1068,7 +1063,7 @@ def __init__(self) -> None:
10681063
10691064 self .motion = tcod .event .MouseMotion ()
10701065 self .mouse_left = self .mouse_middle = self .mouse_right = 0
1071- self .log : List [str ] = []
1066+ self .log : list [str ] = []
10721067
10731068 def on_enter (self ) -> None :
10741069 tcod .mouse_move (320 , 200 )
@@ -1141,15 +1136,15 @@ def __init__(self) -> None:
11411136
11421137 self .curset = 0
11431138 self .delay = 0.0
1144- self .names : List [str ] = []
1145- self .sets : List [str ] = []
1139+ self .names : list [str ] = []
1140+ self .sets : list [str ] = []
11461141
11471142 def on_draw (self ) -> None :
11481143 if not self .sets :
11491144 # parse all *.cfg files in data/namegen
1150- for file in os . listdir ( get_data ( "namegen" )):
1151- if file .find ( ".cfg" ) > 0 :
1152- tcod .namegen_parse (get_data ( os . path . join ( "namegen" , file )) )
1145+ for file in ( DATA_DIR / "namegen" ). iterdir ( ):
1146+ if file .suffix == ".cfg" :
1147+ tcod .namegen_parse (file )
11531148 # get the sets list
11541149 self .sets = tcod .namegen_get_sets ()
11551150 print (self .sets )
@@ -1254,7 +1249,7 @@ def on_enter(self) -> None:
12541249 self .frac_t : float = RES_V - 1
12551250 self .abs_t : float = RES_V - 1
12561251 # light and current color of the tunnel texture
1257- self .lights : List [Light ] = []
1252+ self .lights : list [Light ] = []
12581253 self .tex_r = 0.0
12591254 self .tex_g = 0.0
12601255 self .tex_b = 0.0
0 commit comments