Skip to content

Commit

Permalink
Fix more samples deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
HexDecimal committed Jul 10, 2023
1 parent abdb169 commit c7936eb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions examples/samples_tcod.py
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

import copy
import importlib.metadata
import math
import random
import sys
Expand All @@ -18,6 +19,7 @@
from numpy.typing import NDArray

import tcod.cffi
import tcod.context
import tcod.event
import tcod.noise
import tcod.render
Expand Down Expand Up @@ -160,8 +162,8 @@ def print_banner(self) -> None:
string="The Doryen library uses 24 bits colors, for both " "background and foreground.",
fg=WHITE,
bg=GREY,
bg_blend=tcod.BKGND_MULTIPLY,
alignment=tcod.CENTER,
bg_blend=libtcodpy.BKGND_MULTIPLY,
alignment=libtcodpy.CENTER,
)


Expand Down Expand Up @@ -297,7 +299,7 @@ def on_draw(self) -> None:
# in python the easiest way is to use the line iterator
for x, y in tcod.los.bresenham((xo, yo), (xd, yd)).tolist():
if 0 <= x < sample_console.width and 0 <= y < sample_console.height:
tcod.console_set_char_background(sample_console, x, y, LIGHT_BLUE, self.bk_flag)
libtcodpy.console_set_char_background(sample_console, x, y, LIGHT_BLUE, self.bk_flag)
sample_console.print(
2,
2,
Expand Down Expand Up @@ -581,8 +583,8 @@ def on_draw(self) -> None:
self.draw_ui()
sample_console.print(self.player_x, self.player_y, "@")
# Draw windows.
sample_console.tiles_rgb["ch"][SAMPLE_MAP == "="] = 0x2550 # BOX DRAWINGS DOUBLE HORIZONTAL
sample_console.tiles_rgb["fg"][SAMPLE_MAP == "="] = BLACK
sample_console.rgb["ch"][SAMPLE_MAP == "="] = 0x2550 # BOX DRAWINGS DOUBLE HORIZONTAL
sample_console.rgb["fg"][SAMPLE_MAP == "="] = BLACK

# Get a 2D boolean array of visible cells.
fov = tcod.map.compute_fov(
Expand Down Expand Up @@ -625,7 +627,7 @@ def on_draw(self) -> None:
dark_bg: NDArray[np.float16] = self.dark_map_bg.astype(np.float16)

# Linear interpolation between colors.
sample_console.tiles_rgb["bg"] = dark_bg + (light_bg - dark_bg) * light[..., np.newaxis]
sample_console.rgb["bg"] = dark_bg + (light_bg - dark_bg) * light[..., np.newaxis]
else:
sample_console.bg[...] = np.where(fov[:, :, np.newaxis], self.light_map_bg, self.dark_map_bg)

Expand Down Expand Up @@ -1411,7 +1413,7 @@ def init_context(renderer: int) -> None:
context = tcod.context.new(
columns=root_console.width,
rows=root_console.height,
title=f"python-tcod samples (python-tcod {tcod.__version__}, libtcod {libtcod_version})",
title=f"""python-tcod samples (python-tcod {importlib.metadata.version("tcod")}, libtcod {libtcod_version})""",
vsync=False, # VSync turned off since this is for benchmarking.
tileset=tileset,
)
Expand Down

0 comments on commit c7936eb

Please sign in to comment.