Map code #2
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
from typing import Any, List, Optional, TypeVar, Callable, Type, cast
from uuid import UUID
T = TypeVar("T")
def from_list(f: Callable[[Any], T], x: Any) -> List[T]:
assert isinstance(x, list)
return [f(y) for y in x]
def to_class(c: Type[T], x: Any) -> dict:
assert isinstance(x, c)
return cast(Any, x).to_dict()
def from_str(x: Any) -> str:
assert isinstance(x, str)
return x
def from_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def from_none(x: Any) -> Any:
assert x is None
return x
def from_union(fs, x):
for f in fs:
try:
return f(x)
except:
pass
assert False
class WelcomeCustomFields:
pass
class Target:
entity_iid: UUID
layer_iid: UUID
level_iid: UUID
world_iid: UUID
class ButtonCustomFields:
targets: List[Target]
class Button:
id: str
iid: UUID
layer: str
x: int
y: int
width: int
height: int
color: int
custom_fields: ButtonCustomFields
class DoorCustomFields:
locked_with: Optional[str]
class Door:
id: str
iid: UUID
layer: str
x: int
y: int
width: int
height: int
color: int
custom_fields: DoorCustomFields
class ItemCustomFields:
type: str
class Item:
id: str
iid: UUID
layer: str
x: int
y: int
width: int
height: int
color: int
custom_fields: ItemCustomFields
class PlayerCustomFields:
ammo: int
life: int
class Player:
id: str
iid: UUID
layer: str
x: int
y: int
width: int
height: int
color: int
custom_fields: PlayerCustomFields
class Entities:
door: List[Door]
item: List[Item]
button: List[Button]
player: List[Player]
class NeighbourLevel:
level_iid: UUID
dir: str
class Welcome:
identifier: str
unique_identifer: UUID
x: int
y: int
width: int
height: int
bg_color: str
neighbour_levels: List[NeighbourLevel]
custom_fields: WelcomeCustomFields
layers: List[str]
entities: Entities
def welcome_from_dict(s: Any) -> Welcome:
return Welcome.from_dict(s)
def welcome_to_dict(x: Welcome) -> Any:
return to_class(Welcome, x)