Skip to content

Commit

Permalink
Rename WalkPlayerServerPacket.Direction field to direction
Browse files Browse the repository at this point in the history
  • Loading branch information
Cirras committed Dec 18, 2023
1 parent 0d554b2 commit c03eda6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `WalkPlayerServerPacket.direction` field.

### Changed

- Remove trailing break from `ArenaSpecServerPacket`.
- Remove trailing break from `ArenaAcceptServerPacket`.
- Deprecate `WalkPlayerServerPacket.Direction` field.

## [1.0.0] - 2023-11-07

Expand Down
2 changes: 1 addition & 1 deletion eo-protocol
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ plugins:
summary: true
filters: ["!^_[^_]", "!^__repr__$", "!^__all__$"]
markdown_extensions:
- admonition
- attr_list
51 changes: 51 additions & 0 deletions protocol_code_generator/generate/field_code_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import namedtuple
from protocol_code_generator.generate.code_block import CodeBlock
from protocol_code_generator.generate.object_code_generator import FieldData
from protocol_code_generator.type.basic_type import BasicType
Expand All @@ -13,6 +14,19 @@
from protocol_code_generator.util.docstring_utils import generate_docstring
from protocol_code_generator.util.number_utils import try_parse_int

DeprecatedField = namedtuple(
"DeprecatedField", ["type_name", "old_field_name", "new_field_name", "since"]
)

DEPRECATED_FIELDS = [DeprecatedField("WalkPlayerServerPacket", "Direction", "direction", "1.1.0")]


def get_deprecated_field(type_name, field_name):
for field in DEPRECATED_FIELDS:
if field.type_name == type_name and field.new_field_name == field_name:
return field
return None


class FieldCodeGenerator:
def __init__(
Expand Down Expand Up @@ -233,6 +247,43 @@ def generate_field(self):
setter.unindent()
self._data.add_method(setter)

deprecated = get_deprecated_field(self._data.class_name, self._name)
if deprecated is not None:
old_name = deprecated.old_field_name
deprecated_docstring = (
CodeBlock()
.add_line('"""')
.add_line('!!! warning "Deprecated"')
.add_line()
.add_line(f" Use `{self._name}` instead. (Deprecated since v{deprecated.since})")
.add_line('"""')
)
deprecation_warning = (
f"'{self._data.class_name}.{deprecated.old_field_name}' is deprecated as of "
f"{deprecated.since}, use '{self._name}' instead."
)
self._data.add_method(
CodeBlock()
.add_line('@property')
.add_line(f'def {old_name}(self) -> {python_type_name}:')
.indent()
.add_code_block(deprecated_docstring)
.add_line(f'warn("{deprecation_warning}", DeprecationWarning, stacklevel=2)')
.add_line(f'return self.{self._name}')
.unindent()
.add_import("warn", "warnings")
)
if self._hardcoded_value is None:
self._data.add_method(
CodeBlock()
.add_line(f'@{old_name}.setter')
.add_line(f'def {old_name}(self, {self._name}: {python_type_name}) -> None:')
.indent()
.add_code_block(deprecated_docstring)
.add_line(f'self.{self._name} = {self._name}')
.unindent()
)

def generate_serialize(self):
self._generate_serialize_missing_optional_guard()
self._generate_serialize_none_not_allowed_error()
Expand Down

0 comments on commit c03eda6

Please sign in to comment.