From 99f9ad1570ada34875e1e6df6166832740965162 Mon Sep 17 00:00:00 2001 From: Dysta Date: Sun, 30 Aug 2026 22:18:44 +0200 Subject: [PATCH 1/2] chore: update readme --- README.md | 14 +++++++------- dofutils/maps/serializer.py | 4 +--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index edbd76c..841bc16 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ # Dofutils Collection of useful things to build Dofus Retro bot/emulator. \ -Written in Python3. Require Python >= 3.8. and [Poetry](https://python-poetry.org/). +Written in Python3. Require Python >= 3.11. ## Installation -use `poetry install dofutils` +add dofutils in your project by using `uv add dofutils`. ## Developpement clone the repos using `git clone` then -use `poetry install` to install the dev dependencies. \ -use `poetry run task test` to launch all tests. \ -use `poetry run task lint` to format the project. \ -use `poetry run task check` to type check the project. \ -use `poetry run task clean` to clean import and var. +use `mise install && mise run install` to install the dev dependencies. \ +use `uv run task test` to launch all tests. \ +use `uv run task lint` to format the project. \ +use `uv run task check` to type check the project. \ +use `uv run task clean` to clean import and var. ## Acknowledgement [Vincent Quatrevieux](https://github.com/vincent4vx) : the author of the original libĀ \ diff --git a/dofutils/maps/serializer.py b/dofutils/maps/serializer.py index e8c4e15..3a54f51 100644 --- a/dofutils/maps/serializer.py +++ b/dofutils/maps/serializer.py @@ -41,9 +41,7 @@ class CellData: class DefaultMapDataSerializer: cell_data_length = 10 - - def __init__(self): - self._cache: dict[str, CellData] | None = None + _cache: dict[str, CellData] | None = None def enable_cache(self) -> None: self._cache = {} From b490064c34f0c7f35a168e7db489b880bb62fe40 Mon Sep 17 00:00:00 2001 From: Dysta Date: Sun, 30 Aug 2026 22:30:30 +0200 Subject: [PATCH 2/2] feat: DefaultMap return self for cache --- dofutils/maps/serializer.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dofutils/maps/serializer.py b/dofutils/maps/serializer.py index 3a54f51..983b086 100644 --- a/dofutils/maps/serializer.py +++ b/dofutils/maps/serializer.py @@ -1,6 +1,7 @@ from __future__ import annotations from dataclasses import dataclass +from typing import Self from dofutils.encoding import Base64, CheckSum, Key from dofutils.maps.constant import CellMovement @@ -29,7 +30,7 @@ class InteractiveObjectData(CellLayerData): rotation: int = 0 -@dataclass(frozen=True) +@dataclass(frozen=True, slots=True) class CellData: line_of_sight: bool movement: CellMovement @@ -41,17 +42,22 @@ class CellData: class DefaultMapDataSerializer: cell_data_length = 10 - _cache: dict[str, CellData] | None = None - def enable_cache(self) -> None: + def __init__(self) -> None: + self._cache: dict[str, CellData] | None = None + + def enable_cache(self) -> Self: self._cache = {} + return self - def disable_cache(self) -> None: + def disable_cache(self) -> Self: self._cache = None + return self def deserialize(self, map_data: str) -> list[CellData]: if len(map_data) % self.cell_data_length: raise ValueError("Invalid map data") + return [self._deserialize_cell(map_data[i : i + 10]) for i in range(0, len(map_data), 10)] def serialize(self, cells: list[CellData]) -> str: @@ -63,6 +69,7 @@ def with_key(self, key: Key | str) -> EncryptedMapDataSerializer: def _deserialize_cell(self, value: str) -> CellData: if self._cache is not None and value in self._cache: return self._cache[value] + d = Base64.to_bytes(value) cell = CellData( bool(d[0] & 1), @@ -82,8 +89,10 @@ def _deserialize_cell(self, value: str) -> CellData: ((d[0] & 2) << 12) + ((d[7] & 1) << 12) + (d[8] << 6) + d[9], 0, bool(d[7] & 4), bool(d[7] & 2) ), ) + if self._cache is not None: self._cache[value] = cell + return cell @staticmethod