This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cancerous variant implementation (TODO: MAKE IT BETTER) (NEVER)
- Loading branch information
1 parent
a4b6af6
commit 936b3c5
Showing
6 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .enums import * | ||
from .packet import * | ||
from .variant import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
__all__ = ( | ||
"Variant", | ||
"IntVariant", | ||
"StrVariant", | ||
"TYPE_TO_OBJ_MAPPING", | ||
) | ||
|
||
from growtopia._types import ( | ||
LengthPrefixedStr, | ||
Pack, | ||
TVariant, | ||
TVariantValue, | ||
int8, | ||
int32, | ||
) | ||
from growtopia.net.protocol.enums import ( | ||
VariantType, | ||
) | ||
from growtopia.utils import ( | ||
Packer, | ||
) | ||
|
||
|
||
class Variant: | ||
def __init__( | ||
self, index: int, variant_type: VariantType, variant_value: TVariantValue | None = None | ||
) -> None: | ||
self.index: int = index | ||
self.variant_type: VariantType = variant_type | ||
self.variant_value: TVariantValue | None = variant_value | ||
|
||
def get_size(self) -> int: | ||
if self.variant_type == VariantType.STR: | ||
return 2 + len(self.variant_value) | ||
if self.variant_type == VariantType.INT: | ||
return 6 | ||
|
||
|
||
class IntVariant(Variant, Packer): | ||
index: Pack[int8] | ||
variant_type: Pack[int8] | ||
variant_value: Pack[int32] | ||
|
||
def __init__(self, variant_value: int | None = None) -> None: | ||
Variant.__init__(self, -1, VariantType.INT, variant_value) | ||
|
||
|
||
class StrVariant(Variant, Packer): | ||
index: Pack[int8] | ||
variant_type: Pack[int8] | ||
variant_value: Pack[LengthPrefixedStr] | ||
|
||
def __init__(self, variant_value: str | None = None) -> None: | ||
Variant.__init__(self, -1, VariantType.STR, variant_value) | ||
|
||
|
||
TYPE_TO_OBJ_MAPPING: dict[VariantType, TVariant] = { | ||
VariantType.INT: IntVariant, | ||
VariantType.STR: StrVariant, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
|
||
from typing import ( | ||
Callable, | ||
Self, | ||
Type, | ||
get_origin, | ||
Self, | ||
) | ||
|
||
from growtopia._types import ( | ||
|