Skip to content

Commit 893ce41

Browse files
committed
add objectflags enum
1 parent d66488f commit 893ce41

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ game specific things:
2020
# Changelog
2121

2222
### v1.10
23+
- Added the `ObjectFlags` enum, holding a few known useful flags.
24+
2325
- Moved a few warnings to go through Python's system, so they get attributed to the right place.
2426

2527
- Added a warning for initializing a non-integer slider option with `is_integer=True` (the default).

__init__.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from enum import IntFlag, auto
12
from functools import wraps
23
from pathlib import Path
3-
from typing import Literal, overload
4+
from typing import TYPE_CHECKING, Literal, overload
45

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

128129

130+
class ObjectFlags(IntFlag):
131+
"""
132+
Useful values to assign to object flags, both for directly on an object and in construct_object.
133+
134+
Note that not all flags are known in all games - though the type hinting always contains them
135+
all. Trying to use a flag in a game where it's not known will throw an attribute error.
136+
"""
137+
138+
if TYPE_CHECKING:
139+
# Prevents the object from getting garbage collected
140+
KEEP_ALIVE = auto()
141+
# Allows the object to be referenced by objects in other packages
142+
ALLOW_CROSS_PACKAGE_REFERENCES = auto()
143+
144+
129145
match Game.get_tree():
130146
case Game.Willow1 | Game.Willow2:
131147
ENGINE = unrealsdk.find_object( # pyright: ignore[reportConstantRedefinition]
@@ -142,6 +158,13 @@ def get_pc_willow(*, possibly_loading: bool = False) -> UObject | None: # noqa:
142158

143159
get_pc = get_pc_willow # type: ignore
144160

161+
@wraps(ObjectFlags, updated=())
162+
class WillowObjectFlags(ObjectFlags): # type: ignore
163+
ALLOW_CROSS_PACKAGE_REFERENCES = 0x4
164+
KEEP_ALIVE = 0x4000
165+
166+
ObjectFlags = WillowObjectFlags # type: ignore
167+
145168
case Game.Oak:
146169
ENGINE = unrealsdk.find_object( # pyright: ignore[reportConstantRedefinition]
147170
"OakGameEngine",
@@ -163,3 +186,9 @@ def get_pc_oak(*, possibly_loading: bool = False) -> UObject | None: # noqa: AR
163186
)
164187

165188
get_pc = get_pc_oak # type: ignore
189+
190+
@wraps(ObjectFlags, updated=())
191+
class OakObjectFlags(ObjectFlags): # type: ignore
192+
KEEP_ALIVE = 0x80
193+
194+
ObjectFlags = OakObjectFlags # type: ignore

0 commit comments

Comments
 (0)