Skip to content

Commit

Permalink
We don't need attrs.field() here, they're all kw_only.
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Aug 27, 2023
1 parent 96dc534 commit dfe0c3c
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/editoritems_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ def _unknown_parse(value: str) -> str:
return value


@attrs.define(eq=False, getstate_setstate=False)
@attrs.define(eq=False, kw_only=True, getstate_setstate=False)
class ItemPropKind(Generic[ValueT]):
"""A type of property for an item."""
# Property name for this. This is case-sensitive!
id: str = attrs.field(kw_only=True)
# The translation keyword for this, if it exists.
name: TransToken = attrs.field(kw_only=True)
id: str
# The translation keyword for this, or BLANK if it shouldn't be visible.
name: TransToken
# The instance variable this sets, if any.
instvar: str = attrs.field(kw_only=True)
instvar: str
# All the possible values this can have, if used as a subtype.
# If not usable, this is a zero-length sequence.
subtype_values: Sequence[ValueT] = attrs.field(kw_only=True, default=())
subtype_values: Sequence[ValueT] = ()
# If false, don't show on the default selection window.
allow_user_default: bool = attrs.field(kw_only=True, default=True)
allow_user_default: bool = True

# Functions to parse and export the value.
parse: Callable[[str], ValueT] = attrs.field(kw_only=True)
export: Callable[[ValueT], str] = attrs.field(kw_only=True, default=str)
parse: Callable[[str], ValueT]
export: Callable[[ValueT], str]

@classmethod
def unknown(cls, prop_id: str) -> ItemPropKind[str]:
Expand All @@ -46,6 +46,7 @@ def unknown(cls, prop_id: str) -> ItemPropKind[str]:
name=TransToken.BLANK,
instvar='',
parse=_unknown_parse,
export=str,
allow_user_default=False,
)

Expand Down Expand Up @@ -325,7 +326,7 @@ class GlassTypes(Enum):
# Track Platform prop types:

# Starting state for oscillating Track Platforms
# If non-ocillating, this is disabled.
# If non-oscillating, this is disabled.
prop_track_start_active = bool_prop(
id='StartActive',
instvar='$start_active',
Expand All @@ -344,6 +345,7 @@ class GlassTypes(Enum):
id='StartingPosition',
instvar='$starting_position',
parse=conv_float,
export=str,
name=TransToken.BLANK, # Hidden
)

Expand All @@ -353,6 +355,7 @@ class GlassTypes(Enum):
id='TravelDistance',
instvar='$travel_distance',
parse=conv_float,
export=str,
name=TransToken.BLANK, # Hidden
)

Expand All @@ -364,6 +367,7 @@ class GlassTypes(Enum):
name=TransToken.from_valve('PORTAL2_PuzzleEditor_ContextMenu_paint_type_speed'),
instvar='$speed',
parse=conv_float,
export=str,
)


Expand All @@ -372,6 +376,7 @@ class GlassTypes(Enum):
instvar='$travel_direction',
name=TransToken.BLANK, # Hidden prop
parse=Angle.from_str,
export=str,
)


Expand Down Expand Up @@ -512,7 +517,7 @@ def parse(value: str) -> PaintTypes:
# Specifies if the paint can streak across a surface.
# This actually exports either 0.35 or 0 to the instvar.
prop_paint_allow_streaks = bool_prop(
id = 'AllowStreak',
id='AllowStreak',
instvar='$streak_time',
name=TransToken.from_valve('PORTAL2_PuzzleEditor_ContextMenu_allow_streak_paint'),
)
Expand All @@ -529,13 +534,15 @@ def _parse_connection_count(value: str) -> int:
instvar="$connectioncount",
name=TransToken.from_valve('PORTAL2_PuzzleEditor_ContextMenu_tbeam_activate'),
parse=_parse_connection_count,
export=str,
)
# Specific for funnels, tracks the number of polarity-type input items.
prop_connection_count_polarity = ItemPropKind[int](
id='ConnectionCountPolarity',
instvar="$connectioncountpolarity",
name=TransToken.from_valve('PORTAL2_PuzzleEditor_ContextMenu_tbeam_polarity'),
parse=_parse_connection_count,
export=str,
)


Expand All @@ -550,6 +557,7 @@ def _parse_timer_delay(value: str) -> int:
name=TransToken.from_valve('PORTAL2_PuzzleEditor_ContextMenu_timer_delay'),
subtype_values=range(0, 31),
parse=_parse_timer_delay,
export=str,
)

# Specifies if a pedestal button should play timer sounds.
Expand All @@ -573,6 +581,7 @@ def _parse_timer_delay(value: str) -> int:
instvar='$catapult_speed',
name=TransToken.BLANK, # Not visible.
parse=conv_float,
export=str,
)


Expand All @@ -582,6 +591,7 @@ def _parse_timer_delay(value: str) -> int:
instvar='$indicator_name',
name=TransToken.BLANK, # Inaccessible to users.
parse=str,
export=str,
)


Expand All @@ -599,6 +609,7 @@ def _parse_timer_delay(value: str) -> int:
instvar='$helper_radius',
name=TransToken.BLANK, # Not visible.
parse=conv_float,
export=str,
)


Expand All @@ -624,6 +635,7 @@ def _parse_timer_delay(value: str) -> int:
id='TargetName',
instvar='',
parse=str,
export=str,
name=TransToken.BLANK, # Hidden
)

Expand All @@ -635,6 +647,7 @@ def _parse_timer_delay(value: str) -> int:
name=TransToken.BLANK, # Hidden
instvar='', # None!
parse=str,
export=str,
)


Expand Down

0 comments on commit dfe0c3c

Please sign in to comment.