Skip to content

Commit

Permalink
Tidy ups
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Nov 10, 2023
1 parent 0989a8b commit d54c33d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 43 deletions.
8 changes: 3 additions & 5 deletions src/precomp/cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1885,13 +1885,11 @@ def generate_cubes(vmf: VMF, info: conditions.MapInfo) -> None:
else:
spawn_paint = pair.paint_type

spawn_skin = CUBE_SKINS[pair.cube_type.type].spawn_skin(spawn_paint)
pair.outputs[CubeOutputs.SPAWN].append(Output(
'', '!self', 'RunScriptCode',
'self.SetModel(`{}`); '
'self.__KeyValueFromInt(`skin`, {});'.format(
cust_model,
CUBE_SKINS[pair.cube_type.type].spawn_skin(spawn_paint),
),
f'self.SetModel(`{cust_model}`); '
f'self.__KeyValueFromInt(`skin`, {spawn_skin});',
))

drop_cube = cube = should_respawn = None
Expand Down
26 changes: 11 additions & 15 deletions src/precomp/fizzler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations
from collections import defaultdict
from typing import Iterator, Callable
from typing_extensions import assert_never
from typing_extensions import Self, assert_never
from enum import Enum
import itertools

Expand Down Expand Up @@ -213,7 +213,7 @@ def __attrs_post_init__(self) -> None:
LOGGER.debug('{}: blocks={}, fizzles={}', self.id, self.blocks_portals, self.fizzles_portals)

@classmethod
def parse(cls, conf: Keyvalues):
def parse(cls, conf: Keyvalues) -> Self:
"""Read in a fizzler from a config."""
fizz_id = conf['id']
item_ids = [
Expand Down Expand Up @@ -635,13 +635,13 @@ def __init__(
keys: dict[str, str],
local_keys: dict[str, str],
outputs: list[Output],
thickness: float=2.0,
stretch_center: bool=True,
side_color: Vec=None,
singular: bool=False,
set_axis_var: bool=False,
mat_mod_name: str=None,
mat_mod_var: str=None,
thickness: float = 2.0,
stretch_center: bool = True,
side_color: Vec | None = None,
singular: bool = False,
set_axis_var: bool = False,
mat_mod_name: str | None = None,
mat_mod_var: str | None = None,
) -> None:
self.keys = keys
self.local_keys = local_keys
Expand Down Expand Up @@ -1450,11 +1450,7 @@ def generate_fizzlers(vmf: VMF) -> None:
trigger_hurt_start_disabled = brush_ent['startdisabled']

if brush_type.set_axis_var:
brush_ent['vscript_init_code'] = (
'axis <- `{}`;'.format(
fizz.normal().axis(),
)
)
brush_ent['vscript_init_code'] = f'axis <- `{fizz.normal().axis()}`;'

for out in brush_type.outputs:
new_out = out.copy()
Expand All @@ -1475,7 +1471,7 @@ def generate_fizzlers(vmf: VMF) -> None:
if brush_type.mat_mod_var is not None:
used_tex_func = mat_mod_tex[brush_type].add
else:
def used_tex_func(val):
def used_tex_func(texture: str, /) -> None:
"""If not, ignore those calls."""
return None

Expand Down
25 changes: 10 additions & 15 deletions src/precomp/tiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,8 @@ def __init__(
pos: Vec,
normal: Vec,
base_type: TileType,
subtiles: dict[tuple[int, int], TileType]=None,
has_helper: bool=False,
subtiles: dict[tuple[int, int], TileType] | None = None,
has_helper: bool = False,
) -> None:
self.pos = pos
self.normal = normal
Expand Down Expand Up @@ -878,11 +878,8 @@ def portal_helper_orient(self) -> Vec:
return Vec(1, 0, 0)

def __repr__(self) -> str:
return '<{} TileDef @ {} of {}>'.format(
self.base_type.name,
NORMAL_NAMES.get(self.normal.freeze(), self.normal),
self.pos,
)
norm_name = NORMAL_NAMES.get(self.normal.freeze(), self.normal)
return f'<{self.base_type.name} TileDef @ {norm_name} of {self.pos}>'

def format_tiles(self) -> str:
"""Debug utility, log the subtile shape."""
Expand All @@ -898,8 +895,8 @@ def ensure(
cls,
grid_pos: Vec,
norm: Vec,
tile_type: TileType=TileType.VOID,
) -> 'TileDef':
tile_type: TileType = TileType.VOID,
) -> TileDef:
"""Return a tiledef at a position, creating it with a type if not present."""
try:
tile = TILES[grid_pos.as_tuple(), norm.as_tuple()]
Expand Down Expand Up @@ -1001,8 +998,8 @@ def bind_overlay(self, over: Entity) -> None:
def calc_patterns(
self,
tiles: dict[tuple[int, int], TileType],
is_wall: bool=False,
_pattern: str=None,
is_wall: bool = False,
_pattern: str | None = None,
) -> Iterator[tuple[float, float, float, float, TileSize, TileType]]:
"""Figure out the brushes needed for a complex pattern.
Expand Down Expand Up @@ -1567,8 +1564,7 @@ def make_tile(
assert TILE_TEMP, "make_tile called without data loaded!"
template = TILE_TEMP[normal.as_tuple()]

assert width >= 8 and height >= 8, 'Tile is too small!' \
' ({}x{})'.format(width, height)
assert width >= 8 and height >= 8, f'Tile is too small! ({width}x{height})'
assert thickness in (2, 4, 8), f'Bad thickness {thickness}'

axis_u, axis_v = Vec.INV_AXIS[normal.axis()]
Expand Down Expand Up @@ -1999,8 +1995,7 @@ def find_front_face(
else:
LOGGER.warning('Unknown panel texture "{}"!', face.mat)
return TileType.BLACK, face
else:
raise Exception(f'Malformed wall brush at {grid_pos}, {norm}')
raise Exception(f'Malformed wall brush at {grid_pos}, {norm}')


def inset_flip_panel(panel: list[Solid], pos: Vec, normal: Vec) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_events.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Test the events manager and collections."""
from typing import Dict, no_type_check
from typing import Dict
from unittest.mock import AsyncMock, call, create_autospec

import pytest
Expand Down
1 change: 0 additions & 1 deletion src/ui_tk/corridor_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ def ui_get_buttons(self) -> tuple[GameMode, Direction, Orient]:
@override
def ui_icon_create(self) -> None:
"""Create a new icon widget, and append it to the list."""
index = len(self.icons)
self.icons.append(IconUI(self, len(self.icons)))

@override
Expand Down
2 changes: 1 addition & 1 deletion src/ui_tk/dragdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(
item_height: int,
spacing: int = -1,
yoff: int = 0,
):
) -> None:
self.canvas = canvas
self._place_func = place_func
super().__init__(
Expand Down
9 changes: 4 additions & 5 deletions src/vbsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,16 +550,16 @@ def set_player_portalgun(vmf: VMF, info: corridor.Info) -> None:
'!activator',
'RunScriptCode',
'__pgun_is_oran <- 0; '
'__pgun_port_id <- {}; '
'__pgun_active <- 1'.format(port_id),
f'__pgun_port_id <- {port_id}; '
'__pgun_active <- 1'
),
Output(
'OnStartTouchPortal2',
'!activator',
'RunScriptCode',
'__pgun_is_oran <- 1; '
'__pgun_port_id <- {}; '
'__pgun_active <- 1'.format(port_id),
f'__pgun_port_id <- {port_id}; '
'__pgun_active <- 1'
),
Output(
'OnEndTouchPortal',
Expand Down Expand Up @@ -1532,7 +1532,6 @@ async def main() -> None:
args = " ".join(sys.argv)
new_args = sys.argv[1:]
old_args = sys.argv[1:]
folded_args = [arg.casefold() for arg in old_args]
path = sys.argv[-1] # The path is the last argument to vbsp

if not old_args:
Expand Down

0 comments on commit d54c33d

Please sign in to comment.