Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ game specific things:
# Changelog

### v1.10
- Added the `ObjectFlags` enum, holding a few known useful flags.

- Moved a few warnings to go through Python's system, so they get attributed to the right place.

- Added a warning for initializing a non-integer slider option with `is_integer=True` (the default).
Expand Down
31 changes: 30 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import IntFlag, auto
from functools import wraps
from pathlib import Path
from typing import Literal, overload
from typing import TYPE_CHECKING, Literal, overload

import unrealsdk
from unrealsdk.unreal import UObject
Expand Down Expand Up @@ -126,6 +127,21 @@ def get_pc(*, possibly_loading: bool = False) -> UObject | None:
raise NotImplementedError


class ObjectFlags(IntFlag):
"""
Useful values to assign to object flags, both for directly on an object and in construct_object.

Note that not all flags are known in all games - though the type hinting always contains them
all. Trying to use a flag in a game where it's not known will throw an attribute error.
"""

if TYPE_CHECKING:
# Prevents the object from getting garbage collected
KEEP_ALIVE = auto()
# Allows the object to be referenced by objects in other packages
ALLOW_CROSS_PACKAGE_REFERENCES = auto()


match Game.get_tree():
case Game.Willow1 | Game.Willow2:
ENGINE = unrealsdk.find_object( # pyright: ignore[reportConstantRedefinition]
Expand All @@ -142,6 +158,13 @@ def get_pc_willow(*, possibly_loading: bool = False) -> UObject | None: # noqa:

get_pc = get_pc_willow # type: ignore

@wraps(ObjectFlags, updated=())
class WillowObjectFlags(ObjectFlags): # type: ignore
ALLOW_CROSS_PACKAGE_REFERENCES = 0x4
KEEP_ALIVE = 0x4000

ObjectFlags = WillowObjectFlags # type: ignore

case Game.Oak:
ENGINE = unrealsdk.find_object( # pyright: ignore[reportConstantRedefinition]
"OakGameEngine",
Expand All @@ -163,3 +186,9 @@ def get_pc_oak(*, possibly_loading: bool = False) -> UObject | None: # noqa: AR
)

get_pc = get_pc_oak # type: ignore

@wraps(ObjectFlags, updated=())
class OakObjectFlags(ObjectFlags): # type: ignore
KEEP_ALIVE = 0x80

ObjectFlags = OakObjectFlags # type: ignore