31
31
_console ,
32
32
_fmt ,
33
33
_int ,
34
+ _path_encode ,
34
35
_PropagateException ,
35
36
_unicode ,
36
37
_unpack_char_p ,
@@ -991,7 +992,7 @@ def console_set_custom_font(
991
992
Added PathLike support. `fontFile` no longer takes bytes.
992
993
"""
993
994
fontFile = Path (fontFile ).resolve (strict = True )
994
- _check (lib .TCOD_console_set_custom_font (bytes (fontFile ), flags , nb_char_horiz , nb_char_vertic ))
995
+ _check (lib .TCOD_console_set_custom_font (_path_encode (fontFile ), flags , nb_char_horiz , nb_char_vertic ))
995
996
996
997
997
998
@deprecate ("Check `con.width` instead." )
@@ -1806,7 +1807,7 @@ def console_from_file(filename: str | PathLike[str]) -> tcod.console.Console:
1806
1807
Added PathLike support.
1807
1808
"""
1808
1809
filename = Path (filename ).resolve (strict = True )
1809
- return tcod .console .Console ._from_cdata (_check_p (lib .TCOD_console_from_file (bytes (filename ))))
1810
+ return tcod .console .Console ._from_cdata (_check_p (lib .TCOD_console_from_file (_path_encode (filename ))))
1810
1811
1811
1812
1812
1813
@deprecate ("Call the `Console.blit` method instead." )
@@ -1985,7 +1986,7 @@ def console_load_asc(con: tcod.console.Console, filename: str | PathLike[str]) -
1985
1986
Added PathLike support.
1986
1987
"""
1987
1988
filename = Path (filename ).resolve (strict = True )
1988
- return bool (lib .TCOD_console_load_asc (_console (con ), bytes (filename )))
1989
+ return bool (lib .TCOD_console_load_asc (_console (con ), _path_encode (filename )))
1989
1990
1990
1991
1991
1992
@deprecate ("This format is not actively supported" )
@@ -1998,7 +1999,7 @@ def console_save_asc(con: tcod.console.Console, filename: str | PathLike[str]) -
1998
1999
.. versionchanged:: 16.0
1999
2000
Added PathLike support.
2000
2001
"""
2001
- return bool (lib .TCOD_console_save_asc (_console (con ), bytes (Path (filename ))))
2002
+ return bool (lib .TCOD_console_save_asc (_console (con ), _path_encode (Path (filename ))))
2002
2003
2003
2004
2004
2005
@deprecate ("This format is not actively supported" )
@@ -2012,7 +2013,7 @@ def console_load_apf(con: tcod.console.Console, filename: str | PathLike[str]) -
2012
2013
Added PathLike support.
2013
2014
"""
2014
2015
filename = Path (filename ).resolve (strict = True )
2015
- return bool (lib .TCOD_console_load_apf (_console (con ), bytes (filename )))
2016
+ return bool (lib .TCOD_console_load_apf (_console (con ), _path_encode (filename )))
2016
2017
2017
2018
2018
2019
@deprecate ("This format is not actively supported" )
@@ -2025,7 +2026,7 @@ def console_save_apf(con: tcod.console.Console, filename: str | PathLike[str]) -
2025
2026
.. versionchanged:: 16.0
2026
2027
Added PathLike support.
2027
2028
"""
2028
- return bool (lib .TCOD_console_save_apf (_console (con ), bytes (Path (filename ))))
2029
+ return bool (lib .TCOD_console_save_apf (_console (con ), _path_encode (Path (filename ))))
2029
2030
2030
2031
2031
2032
@deprecate ("Use tcod.console.load_xp to load this file." )
@@ -2040,7 +2041,7 @@ def console_load_xp(con: tcod.console.Console, filename: str | PathLike[str]) ->
2040
2041
Added PathLike support.
2041
2042
"""
2042
2043
filename = Path (filename ).resolve (strict = True )
2043
- return bool (lib .TCOD_console_load_xp (_console (con ), bytes (filename )))
2044
+ return bool (lib .TCOD_console_load_xp (_console (con ), _path_encode (filename )))
2044
2045
2045
2046
2046
2047
@deprecate ("Use tcod.console.save_xp to save this console." )
@@ -2050,7 +2051,7 @@ def console_save_xp(con: tcod.console.Console, filename: str | PathLike[str], co
2050
2051
.. versionchanged:: 16.0
2051
2052
Added PathLike support.
2052
2053
"""
2053
- return bool (lib .TCOD_console_save_xp (_console (con ), bytes (Path (filename )), compress_level ))
2054
+ return bool (lib .TCOD_console_save_xp (_console (con ), _path_encode (Path (filename )), compress_level ))
2054
2055
2055
2056
2056
2057
@deprecate ("Use tcod.console.load_xp to load this file." )
@@ -2061,7 +2062,7 @@ def console_from_xp(filename: str | PathLike[str]) -> tcod.console.Console:
2061
2062
Added PathLike support.
2062
2063
"""
2063
2064
filename = Path (filename ).resolve (strict = True )
2064
- return tcod .console .Console ._from_cdata (_check_p (lib .TCOD_console_from_xp (bytes (filename ))))
2065
+ return tcod .console .Console ._from_cdata (_check_p (lib .TCOD_console_from_xp (_path_encode (filename ))))
2065
2066
2066
2067
2067
2068
@deprecate ("Use tcod.console.load_xp to load this file." )
@@ -2074,7 +2075,7 @@ def console_list_load_xp(
2074
2075
Added PathLike support.
2075
2076
"""
2076
2077
filename = Path (filename ).resolve (strict = True )
2077
- tcod_list = lib .TCOD_console_list_from_xp (bytes (filename ))
2078
+ tcod_list = lib .TCOD_console_list_from_xp (_path_encode (filename ))
2078
2079
if tcod_list == ffi .NULL :
2079
2080
return None
2080
2081
try :
@@ -2102,7 +2103,7 @@ def console_list_save_xp(
2102
2103
try :
2103
2104
for console in console_list :
2104
2105
lib .TCOD_list_push (tcod_list , _console (console ))
2105
- return bool (lib .TCOD_console_list_save_xp (tcod_list , bytes (Path (filename )), compress_level ))
2106
+ return bool (lib .TCOD_console_list_save_xp (tcod_list , _path_encode (Path (filename )), compress_level ))
2106
2107
finally :
2107
2108
lib .TCOD_list_delete (tcod_list )
2108
2109
@@ -3436,7 +3437,7 @@ def mouse_get_status() -> Mouse:
3436
3437
3437
3438
@pending_deprecate ()
3438
3439
def namegen_parse (filename : str | PathLike [str ], random : tcod .random .Random | None = None ) -> None :
3439
- lib .TCOD_namegen_parse (bytes (Path (filename )), random or ffi .NULL )
3440
+ lib .TCOD_namegen_parse (_path_encode (Path (filename )), random or ffi .NULL )
3440
3441
3441
3442
3442
3443
@pending_deprecate ()
@@ -3639,7 +3640,7 @@ def _pycall_parser_error(msg: Any) -> None:
3639
3640
def parser_run (parser : Any , filename : str | PathLike [str ], listener : Any = None ) -> None :
3640
3641
global _parser_listener
3641
3642
if not listener :
3642
- lib .TCOD_parser_run (parser , bytes (Path (filename )), ffi .NULL )
3643
+ lib .TCOD_parser_run (parser , _path_encode (Path (filename )), ffi .NULL )
3643
3644
return
3644
3645
3645
3646
propagate_manager = _PropagateException ()
@@ -3658,7 +3659,7 @@ def parser_run(parser: Any, filename: str | PathLike[str], listener: Any = None)
3658
3659
with _parser_callback_lock :
3659
3660
_parser_listener = listener
3660
3661
with propagate_manager :
3661
- lib .TCOD_parser_run (parser , bytes (Path (filename )), c_listener )
3662
+ lib .TCOD_parser_run (parser , _path_encode (Path (filename )), c_listener )
3662
3663
3663
3664
3664
3665
@deprecate ("libtcod objects are deleted automatically." )
@@ -4079,7 +4080,7 @@ def sys_save_screenshot(name: str | PathLike[str] | None = None) -> None:
4079
4080
.. versionchanged:: 16.0
4080
4081
Added PathLike support.
4081
4082
"""
4082
- lib .TCOD_sys_save_screenshot (bytes (Path (name )) if name is not None else ffi .NULL )
4083
+ lib .TCOD_sys_save_screenshot (_path_encode (Path (name )) if name is not None else ffi .NULL )
4083
4084
4084
4085
4085
4086
# custom fullscreen resolution
0 commit comments