objectionengine2 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- objectionengine2/MovieKit.py +615 -0
- objectionengine2/__init__.py +3 -0
- objectionengine2/ace_attorney_scene.py +1718 -0
- objectionengine2/beans/comment.py +22 -0
- objectionengine2/beans/text.py +9 -0
- objectionengine2/cache.py +18 -0
- objectionengine2/composers/compose_gavel_slam.py +72 -0
- objectionengine2/composers/compose_verdict.py +56 -0
- objectionengine2/font_constants.py +37 -0
- objectionengine2/font_tools.py +98 -0
- objectionengine2/gavel_slam.py +80 -0
- objectionengine2/judge_verdict.py +179 -0
- objectionengine2/loading.py +253 -0
- objectionengine2/make_movie.py +133 -0
- objectionengine2/math_helpers.py +22 -0
- objectionengine2/parse_tags.py +213 -0
- objectionengine2/renderer.py +1 -0
- objectionengine2/tag_macros.py +25 -0
- objectionengine2/testimony_indicator.py +113 -0
- objectionengine2/utils.py +94 -0
- objectionengine2/xml_parser.py +279 -0
- objectionengine2-1.0.0.dist-info/METADATA +101 -0
- objectionengine2-1.0.0.dist-info/RECORD +25 -0
- objectionengine2-1.0.0.dist-info/WHEEL +4 -0
- objectionengine2-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
from PIL import Image, ImageDraw, ImageFont
|
|
2
|
+
from os.path import join, exists
|
|
3
|
+
from objectionengine2.MovieKit import SceneObject
|
|
4
|
+
from objectionengine2.loading import ASSETS_FOLDER
|
|
5
|
+
|
|
6
|
+
TESTIMONY_STROKE_WIDTH = 2
|
|
7
|
+
TESTIMONY_INDICATOR_FONT_PATH = join(
|
|
8
|
+
ASSETS_FOLDER, "testimony_indicator", "DINCondensed-Bold.ttf"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
Visible for 43 frames (1.433s)
|
|
13
|
+
Invisible for 10 frames (0.34s)
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestimonyIndicatorTextObject(SceneObject):
|
|
18
|
+
def __init__(self, parent: SceneObject = None, name: str = ""):
|
|
19
|
+
super().__init__(parent, name, (0, 0, 10))
|
|
20
|
+
self.text_visible_time = 1.43
|
|
21
|
+
self.text_invisible_time = 0.34
|
|
22
|
+
self.font = None
|
|
23
|
+
self.time_remaining = self.text_visible_time
|
|
24
|
+
self.text_visible = True
|
|
25
|
+
self.can_be_displayed = False
|
|
26
|
+
|
|
27
|
+
self.stroke_color = (0, 192, 56)
|
|
28
|
+
self.fill_color = (255, 255, 255)
|
|
29
|
+
|
|
30
|
+
if not exists(TESTIMONY_INDICATOR_FONT_PATH):
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
self.font = ImageFont.truetype(TESTIMONY_INDICATOR_FONT_PATH, 32)
|
|
34
|
+
self.set_text("Testimony")
|
|
35
|
+
|
|
36
|
+
def get_text_bbox(self, text: str):
|
|
37
|
+
x1, y1, x2, y2 = self.font.getbbox(text)
|
|
38
|
+
x1 -= TESTIMONY_STROKE_WIDTH
|
|
39
|
+
y1 -= TESTIMONY_STROKE_WIDTH
|
|
40
|
+
x2 += TESTIMONY_STROKE_WIDTH
|
|
41
|
+
y2 += TESTIMONY_STROKE_WIDTH
|
|
42
|
+
return (x2 - x1, y2 - y1)
|
|
43
|
+
|
|
44
|
+
def set_fill_color(self, color: tuple[int, int, int] = None):
|
|
45
|
+
self.fill_color = color if color is not None else (255, 255, 255)
|
|
46
|
+
self.render_internal_graphic()
|
|
47
|
+
|
|
48
|
+
def set_stroke_color(self, color: tuple[int, int, int] = None):
|
|
49
|
+
self.stroke_color = color if color is not None else (0, 192, 56)
|
|
50
|
+
self.render_internal_graphic()
|
|
51
|
+
|
|
52
|
+
def set_text(self, text: str):
|
|
53
|
+
self._text = text
|
|
54
|
+
self.render_internal_graphic()
|
|
55
|
+
|
|
56
|
+
def render_internal_graphic(self):
|
|
57
|
+
if self.font is None:
|
|
58
|
+
return
|
|
59
|
+
img = Image.new("RGBA", self.get_text_bbox(self._text), (255, 0, 255, 0))
|
|
60
|
+
ctx = ImageDraw.Draw(img)
|
|
61
|
+
ctx.fontmode = "1"
|
|
62
|
+
ctx.text(
|
|
63
|
+
xy=(TESTIMONY_STROKE_WIDTH, TESTIMONY_STROKE_WIDTH),
|
|
64
|
+
text=self._text,
|
|
65
|
+
fill=self.fill_color,
|
|
66
|
+
stroke_width=TESTIMONY_STROKE_WIDTH,
|
|
67
|
+
stroke_fill=self.stroke_color,
|
|
68
|
+
font=self.font,
|
|
69
|
+
anchor="lt",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
self.testimony_img = img.resize(
|
|
73
|
+
(int(round(img.width * 0.65)), img.height),
|
|
74
|
+
resample=Image.Resampling.NEAREST,
|
|
75
|
+
).convert("RGBA")
|
|
76
|
+
|
|
77
|
+
def make_visible(self):
|
|
78
|
+
self.can_be_displayed = True
|
|
79
|
+
self.reset_timing()
|
|
80
|
+
|
|
81
|
+
def make_invisible(self):
|
|
82
|
+
self.can_be_displayed = False
|
|
83
|
+
|
|
84
|
+
def reset_timing(self):
|
|
85
|
+
self.text_visible = True
|
|
86
|
+
self.time_remaining = self.text_visible_time
|
|
87
|
+
|
|
88
|
+
def update(self, delta):
|
|
89
|
+
self.time_remaining -= delta
|
|
90
|
+
|
|
91
|
+
while self.time_remaining < 0.0:
|
|
92
|
+
if self.text_visible:
|
|
93
|
+
self.text_visible = False
|
|
94
|
+
self.time_remaining += self.text_invisible_time
|
|
95
|
+
else:
|
|
96
|
+
self.text_visible = True
|
|
97
|
+
self.time_remaining += self.text_visible_time
|
|
98
|
+
|
|
99
|
+
def render(self, img: Image.Image, ctx: ImageDraw.ImageDraw):
|
|
100
|
+
if self.font is None:
|
|
101
|
+
return
|
|
102
|
+
|
|
103
|
+
if not self.can_be_displayed:
|
|
104
|
+
return
|
|
105
|
+
|
|
106
|
+
if not self.text_visible:
|
|
107
|
+
return
|
|
108
|
+
|
|
109
|
+
img.paste(
|
|
110
|
+
self.testimony_img,
|
|
111
|
+
(int(TESTIMONY_STROKE_WIDTH / 2) - 1, int(TESTIMONY_STROKE_WIDTH / 2) - 1),
|
|
112
|
+
self.testimony_img,
|
|
113
|
+
)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Asset downloads and small helpers for render configuration."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path, PurePosixPath
|
|
4
|
+
from stat import S_ISLNK
|
|
5
|
+
from tempfile import TemporaryDirectory
|
|
6
|
+
import shutil
|
|
7
|
+
import zipfile
|
|
8
|
+
|
|
9
|
+
import requests
|
|
10
|
+
|
|
11
|
+
from .loading import ASSETS_FOLDER, load_music_data
|
|
12
|
+
|
|
13
|
+
_ASSETS_URL = "https://dcmdevassets.blob.core.windows.net/data/oe-assetsv4.zip"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _assets_complete(folder: Path) -> bool:
|
|
17
|
+
return (
|
|
18
|
+
(folder / "characters" / "phoenix" / "phoenix-normal-idle.gif").is_file()
|
|
19
|
+
and (folder / "music" / "pwr").is_dir()
|
|
20
|
+
and (folder / "textbox").is_dir()
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _install_assets(populate) -> None:
|
|
25
|
+
"""Prepare a complete pack inside the cache, then replace the active pack."""
|
|
26
|
+
destination = Path(ASSETS_FOLDER)
|
|
27
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
28
|
+
with TemporaryDirectory(prefix=".assets-", dir=destination.parent) as temporary:
|
|
29
|
+
temporary_path = Path(temporary)
|
|
30
|
+
staged = temporary_path / "assets"
|
|
31
|
+
populate(staged)
|
|
32
|
+
if not _assets_complete(staged):
|
|
33
|
+
raise RuntimeError("The asset pack is incomplete")
|
|
34
|
+
backup = temporary_path / "previous-assets"
|
|
35
|
+
had_previous = destination.exists() or destination.is_symlink()
|
|
36
|
+
if had_previous:
|
|
37
|
+
destination.replace(backup)
|
|
38
|
+
try:
|
|
39
|
+
staged.replace(destination)
|
|
40
|
+
except OSError:
|
|
41
|
+
if had_previous:
|
|
42
|
+
backup.replace(destination)
|
|
43
|
+
raise
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def ensure_assets_are_available() -> None:
|
|
47
|
+
"""Populate the platform cache, reusing a complete legacy local pack."""
|
|
48
|
+
destination = Path(ASSETS_FOLDER)
|
|
49
|
+
if _assets_complete(destination):
|
|
50
|
+
return
|
|
51
|
+
legacy = Path.cwd() / "assets"
|
|
52
|
+
if legacy.resolve() != destination.resolve() and _assets_complete(legacy):
|
|
53
|
+
_install_assets(lambda staged: shutil.copytree(legacy, staged))
|
|
54
|
+
else:
|
|
55
|
+
download_assets()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def download_assets() -> None:
|
|
59
|
+
"""Download the asset pack into the platform cache."""
|
|
60
|
+
print("Assets not present in cache. Downloading them")
|
|
61
|
+
|
|
62
|
+
def populate(staged: Path) -> None:
|
|
63
|
+
archive_path = staged.parent / "assets.zip"
|
|
64
|
+
response = requests.get(_ASSETS_URL, stream=True, timeout=120)
|
|
65
|
+
try:
|
|
66
|
+
response.raise_for_status()
|
|
67
|
+
with archive_path.open("wb") as archive_file:
|
|
68
|
+
for chunk in response.iter_content(chunk_size=1024 * 1024):
|
|
69
|
+
archive_file.write(chunk)
|
|
70
|
+
finally:
|
|
71
|
+
response.close()
|
|
72
|
+
with zipfile.ZipFile(archive_path) as archive:
|
|
73
|
+
for item in archive.infolist():
|
|
74
|
+
entry = PurePosixPath(item.filename)
|
|
75
|
+
if (
|
|
76
|
+
entry.is_absolute()
|
|
77
|
+
or ".." in entry.parts
|
|
78
|
+
or "\\" in item.filename
|
|
79
|
+
or ":" in item.filename
|
|
80
|
+
or S_ISLNK(item.external_attr >> 16)
|
|
81
|
+
):
|
|
82
|
+
raise ValueError(f"Unsafe path in asset archive: {item.filename!r}")
|
|
83
|
+
archive.extractall(staged)
|
|
84
|
+
|
|
85
|
+
_install_assets(populate)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def get_all_music_available() -> list[str]:
|
|
89
|
+
ensure_assets_are_available()
|
|
90
|
+
return [*load_music_data().keys(), "rnd"]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def is_music_available(music: str) -> bool:
|
|
94
|
+
return music.lower() in get_all_music_available()
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import xml.sax
|
|
2
|
+
from .parse_tags import (
|
|
3
|
+
BaseDialogueItem,
|
|
4
|
+
DialoguePage,
|
|
5
|
+
DialogueTextChunk,
|
|
6
|
+
DialogueAction,
|
|
7
|
+
DialogueTextLineBreak,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Handler(xml.sax.ContentHandler):
|
|
12
|
+
pages: list[DialoguePage] = []
|
|
13
|
+
__current_page_contents: list[BaseDialogueItem] | None = None
|
|
14
|
+
__color_stack: list[str] = []
|
|
15
|
+
|
|
16
|
+
def __init__(self) -> None:
|
|
17
|
+
self.pages = []
|
|
18
|
+
self.__color_stack = []
|
|
19
|
+
|
|
20
|
+
def startElement(self, name: str, attrs: xml.sax.xmlreader.AttributesImpl):
|
|
21
|
+
attrs_dict = {n: attrs.getValue(n) for n in attrs.getNames()}
|
|
22
|
+
# print(f"startElement {name=} {attrs_dict=}")
|
|
23
|
+
if name == "page":
|
|
24
|
+
if self.__current_page_contents is None:
|
|
25
|
+
self.__current_page_contents = []
|
|
26
|
+
else:
|
|
27
|
+
raise Exception("Pages cannot be nested")
|
|
28
|
+
elif name == "br":
|
|
29
|
+
self.__current_page_contents.append(DialogueTextLineBreak())
|
|
30
|
+
elif name == "sp":
|
|
31
|
+
self.__current_page_contents.append(DialogueTextChunk(" ", []))
|
|
32
|
+
elif name == "startblip":
|
|
33
|
+
gender = attrs_dict.get("gender", "male")
|
|
34
|
+
self.__current_page_contents.append(
|
|
35
|
+
DialogueAction(f"startblip {gender}", 0)
|
|
36
|
+
)
|
|
37
|
+
elif name == "stopblip":
|
|
38
|
+
self.__current_page_contents.append(DialogueAction(f"stopblip", 0))
|
|
39
|
+
elif name == "sprite":
|
|
40
|
+
position = attrs_dict.get("position")
|
|
41
|
+
if position is None:
|
|
42
|
+
raise Exception("`<sprite/>` tag needs `position` attribute")
|
|
43
|
+
|
|
44
|
+
src = attrs_dict.get("src")
|
|
45
|
+
if src is None:
|
|
46
|
+
raise Exception("`<sprite/>` tag needs `src` attribute")
|
|
47
|
+
|
|
48
|
+
self.__current_page_contents.append(
|
|
49
|
+
DialogueAction(f"sprite {position} {src}", 0)
|
|
50
|
+
)
|
|
51
|
+
elif name == "wait":
|
|
52
|
+
duration = attrs_dict.get("duration")
|
|
53
|
+
if duration is None:
|
|
54
|
+
raise Exception("`<wait/>` tag needs `duration` attribute")
|
|
55
|
+
|
|
56
|
+
self.__current_page_contents.append(DialogueAction(f"wait {duration}", 0))
|
|
57
|
+
elif name == "bubble":
|
|
58
|
+
type = attrs_dict.get("type", "objection")
|
|
59
|
+
character = attrs_dict.get("character", "None")
|
|
60
|
+
self.__current_page_contents.append(
|
|
61
|
+
DialogueAction(f"bubble {type} {character}", 0)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
elif name == "showarrow":
|
|
65
|
+
self.__current_page_contents.append(DialogueAction("showarrow", 0))
|
|
66
|
+
|
|
67
|
+
elif name == "hidearrow":
|
|
68
|
+
self.__current_page_contents.append(DialogueAction("hidearrow", 0))
|
|
69
|
+
|
|
70
|
+
elif name == "showbox":
|
|
71
|
+
self.__current_page_contents.append(DialogueAction("showbox", 0))
|
|
72
|
+
|
|
73
|
+
elif name == "hidebox":
|
|
74
|
+
self.__current_page_contents.append(DialogueAction("hidebox", 0))
|
|
75
|
+
|
|
76
|
+
elif name == "nametag":
|
|
77
|
+
name_text = attrs_dict.get("text")
|
|
78
|
+
if name_text is None:
|
|
79
|
+
raise Exception("`<nametag/>` tag needs `text` attribute")
|
|
80
|
+
|
|
81
|
+
self.__current_page_contents.append(
|
|
82
|
+
DialogueAction(f"nametag {name_text}", 0)
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
elif name == "evidence":
|
|
86
|
+
action = attrs_dict.get("action")
|
|
87
|
+
if action is None:
|
|
88
|
+
raise Exception("`<evidence/>` tag needs `action` attribute")
|
|
89
|
+
|
|
90
|
+
if action == "clear":
|
|
91
|
+
self.__current_page_contents.append(
|
|
92
|
+
DialogueAction(f"evidence clear", 0)
|
|
93
|
+
)
|
|
94
|
+
else:
|
|
95
|
+
src = attrs_dict.get("src")
|
|
96
|
+
if src is None:
|
|
97
|
+
raise Exception("`<evidence/>` tag needs `src` attribute")
|
|
98
|
+
|
|
99
|
+
self.__current_page_contents.append(
|
|
100
|
+
DialogueAction(f"evidence {action} {src}", 0)
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
elif name == "sound":
|
|
104
|
+
src = attrs_dict.get("src")
|
|
105
|
+
if src is None:
|
|
106
|
+
raise Exception("`<sound/>` tag needs `src` attribute")
|
|
107
|
+
|
|
108
|
+
self.__current_page_contents.append(DialogueAction(f"sound {src}", 0))
|
|
109
|
+
|
|
110
|
+
elif name == "shake":
|
|
111
|
+
magnitude_str = attrs_dict.get("magnitude")
|
|
112
|
+
if magnitude_str is None:
|
|
113
|
+
raise Exception("`<shake/>` tag needs `magnitude` attribute")
|
|
114
|
+
|
|
115
|
+
duration_str = attrs_dict.get("duration")
|
|
116
|
+
if duration_str is None:
|
|
117
|
+
raise Exception("`<shake/>` tag needs `duration` attribute")
|
|
118
|
+
|
|
119
|
+
self.__current_page_contents.append(
|
|
120
|
+
DialogueAction(f"shake {magnitude_str} {duration_str}", 0)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
elif name == "flash":
|
|
124
|
+
duration_str = attrs_dict.get("duration")
|
|
125
|
+
if duration_str is None:
|
|
126
|
+
raise Exception("`<flash/>` tag needs `duration` attribute")
|
|
127
|
+
|
|
128
|
+
self.__current_page_contents.append(
|
|
129
|
+
DialogueAction(f"flash {duration_str}", 0)
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
elif name == "music":
|
|
133
|
+
action = attrs_dict.get("action")
|
|
134
|
+
if action is None:
|
|
135
|
+
raise Exception("`<music/>` tag needs `action` attribute")
|
|
136
|
+
if action not in ["start", "stop"]:
|
|
137
|
+
raise Exception(
|
|
138
|
+
'`<music/>` tag\'s `action` attribute must be `"start"` or `"stop"`'
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
if action == "start":
|
|
142
|
+
src = attrs_dict.get("src")
|
|
143
|
+
if src is None:
|
|
144
|
+
raise Exception("`<music/>` tag needs `src` attribute")
|
|
145
|
+
|
|
146
|
+
self.__current_page_contents.append(
|
|
147
|
+
DialogueAction(f"music start {src}", 0)
|
|
148
|
+
)
|
|
149
|
+
elif action == "stop":
|
|
150
|
+
self.__current_page_contents.append(DialogueAction(f"music stop", 0))
|
|
151
|
+
|
|
152
|
+
elif name in ["cut", "pan", "show", "hide"]:
|
|
153
|
+
position = attrs_dict.get("position")
|
|
154
|
+
if position is None:
|
|
155
|
+
raise Exception(f"`<{name}/>` tag needs `position` attribute")
|
|
156
|
+
|
|
157
|
+
self.__current_page_contents.append(DialogueAction(f"{name} {position}", 0))
|
|
158
|
+
|
|
159
|
+
elif name == "verdict":
|
|
160
|
+
action = attrs_dict.get("action")
|
|
161
|
+
if action is None:
|
|
162
|
+
raise Exception("`<verdict/>` tag needs `action` attribute")
|
|
163
|
+
if action == "set":
|
|
164
|
+
new_text = attrs_dict.get("text")
|
|
165
|
+
if new_text is None:
|
|
166
|
+
raise Exception(
|
|
167
|
+
'`<verdict action="set"/>` tag needs `text` attribute'
|
|
168
|
+
)
|
|
169
|
+
color = attrs_dict.get("color")
|
|
170
|
+
if color is None:
|
|
171
|
+
raise Exception(
|
|
172
|
+
'`<verdict action="set"/>` tag needs `color` attribute'
|
|
173
|
+
)
|
|
174
|
+
self.__current_page_contents.append(
|
|
175
|
+
DialogueAction(f'verdict set "{new_text}" {color}', 0)
|
|
176
|
+
)
|
|
177
|
+
elif action == "show":
|
|
178
|
+
index = attrs_dict.get("index")
|
|
179
|
+
if index is None:
|
|
180
|
+
raise Exception(
|
|
181
|
+
'`<verdict action="show"/>` tag needs `index` attribute'
|
|
182
|
+
)
|
|
183
|
+
self.__current_page_contents.append(
|
|
184
|
+
DialogueAction(f"verdict show {index}", 0)
|
|
185
|
+
)
|
|
186
|
+
elif action == "clear":
|
|
187
|
+
self.__current_page_contents.append(DialogueAction("verdict clear", 0))
|
|
188
|
+
else:
|
|
189
|
+
raise Exception(
|
|
190
|
+
'`<verdict/>` tag\'s `action` attribute must be `"set"`, `"show"`, or `"clear"`'
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
elif name == "font":
|
|
194
|
+
color = attrs_dict.get("color")
|
|
195
|
+
self.__color_stack.append(color)
|
|
196
|
+
|
|
197
|
+
elif name == "testimony":
|
|
198
|
+
action = attrs_dict.get("action")
|
|
199
|
+
if action is None:
|
|
200
|
+
raise Exception("`<testimony/>` tag needs `action` attribute")
|
|
201
|
+
|
|
202
|
+
if action == "set":
|
|
203
|
+
new_text = attrs_dict.get("text")
|
|
204
|
+
if new_text is None:
|
|
205
|
+
raise Exception(
|
|
206
|
+
'`<testimony action="set"/>` tag needs `text` attribute'
|
|
207
|
+
)
|
|
208
|
+
self.__current_page_contents.append(
|
|
209
|
+
DialogueAction(f"testimony set '{new_text}'", 0)
|
|
210
|
+
)
|
|
211
|
+
elif action == "show":
|
|
212
|
+
self.__current_page_contents.append(
|
|
213
|
+
DialogueAction(f"testimony show", 0)
|
|
214
|
+
)
|
|
215
|
+
elif action == "hide":
|
|
216
|
+
self.__current_page_contents.append(
|
|
217
|
+
DialogueAction(f"testimony hide", 0)
|
|
218
|
+
)
|
|
219
|
+
elif action == "fillcolor":
|
|
220
|
+
r = attrs_dict.get("r", 0)
|
|
221
|
+
g = attrs_dict.get("g", 0)
|
|
222
|
+
b = attrs_dict.get("b", 0)
|
|
223
|
+
self.__current_page_contents.append(
|
|
224
|
+
DialogueAction(f"testimony fillcolor {r} {g} {b}", 0)
|
|
225
|
+
)
|
|
226
|
+
elif action == "strokecolor":
|
|
227
|
+
r = attrs_dict.get("r", 0)
|
|
228
|
+
g = attrs_dict.get("g", 0)
|
|
229
|
+
b = attrs_dict.get("b", 0)
|
|
230
|
+
self.__current_page_contents.append(
|
|
231
|
+
DialogueAction(f"testimony strokecolor {r} {g} {b}", 0)
|
|
232
|
+
)
|
|
233
|
+
else:
|
|
234
|
+
raise Exception(f"<testimony/> tag has unknown action '{action}'")
|
|
235
|
+
|
|
236
|
+
elif name == "gavel":
|
|
237
|
+
frame = attrs_dict.get("frame", 0)
|
|
238
|
+
if frame is None:
|
|
239
|
+
raise Exception("`<gavel/>` needs `frame` attribute")
|
|
240
|
+
self.__current_page_contents.append(
|
|
241
|
+
DialogueAction(f'gavel {frame}', 0)
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
def endElement(self, name: str):
|
|
245
|
+
# print(f"endElement {name=}")
|
|
246
|
+
if name == "page":
|
|
247
|
+
if isinstance(self.__current_page_contents, list):
|
|
248
|
+
self.pages.append(DialoguePage(self.__current_page_contents))
|
|
249
|
+
self.__current_page_contents = None
|
|
250
|
+
elif self.__current_page_contents is None:
|
|
251
|
+
raise Exception("Page must be started before it can end")
|
|
252
|
+
|
|
253
|
+
elif name == "font":
|
|
254
|
+
self.__color_stack.pop()
|
|
255
|
+
|
|
256
|
+
def characters(self, content: str):
|
|
257
|
+
content = content.strip()
|
|
258
|
+
if len(content.strip()) == 0:
|
|
259
|
+
return
|
|
260
|
+
|
|
261
|
+
content = content.replace("!nbsp;", " ")
|
|
262
|
+
tags = []
|
|
263
|
+
if len(self.__color_stack) > 0:
|
|
264
|
+
tags.append(self.__color_stack[-1])
|
|
265
|
+
self.__current_page_contents.append(DialogueTextChunk(content, tags))
|
|
266
|
+
|
|
267
|
+
def startDocument(self):
|
|
268
|
+
self.pages = []
|
|
269
|
+
self.__color_stack = []
|
|
270
|
+
self.__current_page_contents = None
|
|
271
|
+
|
|
272
|
+
def endDocument(self):
|
|
273
|
+
return super().endDocument()
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def parse_script(source_script: str) -> list[DialoguePage]:
|
|
277
|
+
h = Handler()
|
|
278
|
+
xml.sax.parse(source_script, h)
|
|
279
|
+
return h.pages
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: objectionengine2
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Independent continuation of Objection Engine for rendering Ace Attorney scenes
|
|
5
|
+
Author: Luis Mayo Valbuena, Malcolm Anderson
|
|
6
|
+
Author-email: Luis Mayo Valbuena <luismayovalbuena@outlook.es>, Malcolm Anderson <malcolminyo@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: pillow>=10.4,<13
|
|
10
|
+
Requires-Dist: pydub>=0.25.1,<0.26
|
|
11
|
+
Requires-Dist: audioop-lts>=0.2.2,<0.3 ; python_full_version >= '3.13'
|
|
12
|
+
Requires-Dist: ffmpeg-python>=0.2,<0.3
|
|
13
|
+
Requires-Dist: spacy>=3.8.16,<3.9
|
|
14
|
+
Requires-Dist: opencv-python-headless>=4.14,<5
|
|
15
|
+
Requires-Dist: fonttools>=4.60,<5
|
|
16
|
+
Requires-Dist: numpy>=2.2,<3
|
|
17
|
+
Requires-Dist: rich>=14,<16
|
|
18
|
+
Requires-Dist: requests>=2.32,<3
|
|
19
|
+
Requires-Dist: platformdirs>=4.4,<5
|
|
20
|
+
Requires-Dist: toml>=0.10.2,<0.11
|
|
21
|
+
Requires-Dist: transformers>=4.55,<6 ; extra == 'sentiment'
|
|
22
|
+
Requires-Dist: torch>=2.8,<3 ; extra == 'sentiment'
|
|
23
|
+
Requires-Dist: sentencepiece>=0.2,<0.3 ; extra == 'sentiment'
|
|
24
|
+
Requires-Dist: protobuf>=5,<7 ; extra == 'sentiment'
|
|
25
|
+
Requires-Python: >=3.10, <3.15
|
|
26
|
+
Project-URL: Original, https://github.com/LuisMayo/objection_engine
|
|
27
|
+
Provides-Extra: sentiment
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# objectionengine2
|
|
31
|
+
|
|
32
|
+
objectionengine2 converts comment chains and scripted dialogue into Ace Attorney style videos. It is an independent continuation of [Objection Engine](https://github.com/LuisMayo/objection_engine), originally created by Luis Mayo Valbuena. The original copyright and MIT license are preserved in `LICENSE`.
|
|
33
|
+
|
|
34
|
+
The distribution, repository, and Python import are all named `objectionengine2`. Update existing `objection_engine` imports when migrating scripts.
|
|
35
|
+
|
|
36
|
+
## Requirements
|
|
37
|
+
|
|
38
|
+
- Python 3.10 through 3.14
|
|
39
|
+
- FFmpeg and `ffprobe` on `PATH`
|
|
40
|
+
- The Objection Engine asset pack. The renderer downloads it on first use into
|
|
41
|
+
the user cache directory selected by `platformdirs` for `objectionengine2`.
|
|
42
|
+
An existing complete `./assets/` pack is copied there on first use.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
From a clone, sync the locked environment with `uv`:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
uv sync --python 3.14 --locked
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The package supports Python 3.10–3.14; `.python-version` selects 3.14 by default. To enable Hugging Face sentiment, add `--extra sentiment` to the run command, for example `uv run --locked --extra sentiment python examples/example_easy.py`. This downloads a model on first use into the same user cache under `models/`. The base installation does not need a model. Find the cache location with `uv run python -c 'from objectionengine2.cache import cache_path; print(cache_path())'`.
|
|
53
|
+
|
|
54
|
+
## Render comments
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from objectionengine2.beans.comment import Comment
|
|
58
|
+
from objectionengine2.renderer import render_comment_list
|
|
59
|
+
|
|
60
|
+
comments = [
|
|
61
|
+
Comment(user_name="Phoenix", text_content="The defense is ready."),
|
|
62
|
+
Comment(user_name="Edgeworth", text_content="The prosecution is ready."),
|
|
63
|
+
]
|
|
64
|
+
render_comment_list(comments, output_filename="outputs/output.mp4")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Run `uv run python examples/example_easy.py` from the repository root for a complete example. Additional scene, XML, and casting examples are in `examples/`; reference documentation is in `docs/`. Pass an `output_filename` in an existing directory. Scripts with literal `assets/...` paths still need a local asset directory; generated comment dialogue uses the user cache.
|
|
68
|
+
|
|
69
|
+
## Sentiment settings
|
|
70
|
+
|
|
71
|
+
By default, dialogue uses neutral sentiment and needs no machine learning dependency. Explicit `Comment(score=...)` values still select positive or negative sprites. Set `oe_sentiment_model=hf` after installing the `sentiment` extra to use the Hugging Face model. Setting `oe_bypass_sentiment` to a nonempty value forces neutral sentiment. The former Polyglot mode is no longer supported; an unsupported `oe_sentiment_model` value raises a clear error.
|
|
72
|
+
|
|
73
|
+
Set `OE_DIRECT_H264_ENCODING=true` only if your OpenCV build provides an H.264 encoder. The default path encodes the intermediate video with OpenCV and creates the final H.264/AAC MP4 with FFmpeg.
|
|
74
|
+
|
|
75
|
+
## Container (Podman)
|
|
76
|
+
|
|
77
|
+
The Docker image uses Python 3.14 and includes FFmpeg. Build and run the included example from the repository root:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
podman build -t objectionengine2 .
|
|
81
|
+
podman volume create objectionengine2-cache
|
|
82
|
+
podman run --rm \
|
|
83
|
+
--mount type=volume,src=objectionengine2-cache,dst=/root/.cache/objectionengine2 \
|
|
84
|
+
--mount type=bind,src="$(pwd)/outputs",dst=/app/outputs \
|
|
85
|
+
objectionengine2
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The result is `outputs/output.mp4`. Ensure `outputs/` exists before running;
|
|
89
|
+
the image saves downloaded assets and models in the mounted cache volume.
|
|
90
|
+
To run your own script, mount it at `/app/render.py` and add `render.py` after
|
|
91
|
+
the image name. Have the script write into `outputs/`.
|
|
92
|
+
|
|
93
|
+
## Tests
|
|
94
|
+
|
|
95
|
+
`uv sync --locked` installs the default `dev` group, including pytest. Run `uv run --locked pytest -q` for offline tests. They generate their own small media inputs and require FFmpeg and `ffprobe` but do not download assets or models.
|
|
96
|
+
|
|
97
|
+
For a complete courtroom smoke test, run `uv run --locked pytest -q -m asset_integration`. The test calls `ensure_assets_are_available()` from `objectionengine2.utils` first, which populates the platform cache if needed. Keep that cache to avoid downloading the pack again.
|
|
98
|
+
|
|
99
|
+
## Contributing
|
|
100
|
+
|
|
101
|
+
Changes and fixes are welcome. Please run the offline suite before opening a pull request.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
objectionengine2/MovieKit.py,sha256=bEuM2JXCfY8g0kJ0F9Gyffo82VPtph6_BvpvMsg0xJM,19713
|
|
2
|
+
objectionengine2/__init__.py,sha256=PGXG83jqWFuTtnKJbh6YhQGN2Efw_kc-gBNJyVUyVj4,132
|
|
3
|
+
objectionengine2/ace_attorney_scene.py,sha256=erdbhHBN9GLp4PEFz76MAhZzKHbzSL0xeEjtt1Oi6fI,63860
|
|
4
|
+
objectionengine2/beans/comment.py,sha256=GulyaGk0Ycgd2X8RCpBV3ch3Rcf5Cg4brxdQOYDPIhA,837
|
|
5
|
+
objectionengine2/beans/text.py,sha256=er3niCtFKa5_6UzNauxfgbpXKs0YBWB7K19NZziqdJc,388
|
|
6
|
+
objectionengine2/cache.py,sha256=V7-CGjEI65S1MZh9P4eywdBp2DmZ6KJyYkjeWENa85A,423
|
|
7
|
+
objectionengine2/composers/compose_gavel_slam.py,sha256=2jbavmTy388M2Z3ZKjHhirpgJvFybQlPk98q1hA-XGo,2337
|
|
8
|
+
objectionengine2/composers/compose_verdict.py,sha256=CApjjPGIhdNHVf9tbp8UHSNXB8U3Iu9TXWfyNHzNRLg,1948
|
|
9
|
+
objectionengine2/font_constants.py,sha256=Jo3FbwZM8v7dMqTJJhwrprJW7O66cFtCOgvaBLhegxU,1389
|
|
10
|
+
objectionengine2/font_tools.py,sha256=unwa5hv-RAtEzOlFNZs9JTckm8hTH8vb3KT9BCkuf-M,3326
|
|
11
|
+
objectionengine2/gavel_slam.py,sha256=uyvrkEaemxlelQKOAmBJ4G3fW-P3lqD3lGhAgtwH7mI,2472
|
|
12
|
+
objectionengine2/judge_verdict.py,sha256=xc7qfSZeZdi3zm4gTV6qbSHIbrkfV9SwGFrKhw42VrI,6001
|
|
13
|
+
objectionengine2/loading.py,sha256=KVAFRJwlOF1yVARzLBW8TaZRjBHvlXSviLCWywmahj0,10054
|
|
14
|
+
objectionengine2/make_movie.py,sha256=xsGs4Ud60zCAZWMjjcSCqdNH7rXOcX8LF0NP7-sZMIQ,4441
|
|
15
|
+
objectionengine2/math_helpers.py,sha256=GY_wKpRPeVCwhWd_bZuY0IP2vkGEEw5j1HdW8hywdek,670
|
|
16
|
+
objectionengine2/parse_tags.py,sha256=lp4YYNNIDFQ425yB803vT6MSCTK9EPpOqNXk-5notqw,7646
|
|
17
|
+
objectionengine2/renderer.py,sha256=WSZD29DoeTnupu0DR3rLucxiKY3A2UZA0jo7l6uyUQg,43
|
|
18
|
+
objectionengine2/tag_macros.py,sha256=Ox1ZSY03QrMbp_9WLVQdP9IaHpB-GcPpLQKfuxVAjrQ,1063
|
|
19
|
+
objectionengine2/testimony_indicator.py,sha256=DCm11Wh27qk7WPO1rt8PAdyNdxoxeIDMRh07hpoDHoI,3545
|
|
20
|
+
objectionengine2/utils.py,sha256=okRYpmdSiukacAc_kVjwYs_MigMAzRZ0NS951bancps,3298
|
|
21
|
+
objectionengine2/xml_parser.py,sha256=QEQGl0nb1a-wDXWaeMyGSSyaI9w_AJojFcrrq8Xzqeo,10741
|
|
22
|
+
objectionengine2-1.0.0.dist-info/licenses/LICENSE,sha256=xdKAyIzzM9Xb-1exAvgj08fQI8TrnyT9doTn1NBX5Zo,1075
|
|
23
|
+
objectionengine2-1.0.0.dist-info/WHEEL,sha256=nQ0eT7mepDP-DkLACRDiCUi7cAIJyLg4OevuC4KpLLY,80
|
|
24
|
+
objectionengine2-1.0.0.dist-info/METADATA,sha256=m85AKkYBCemT9FFLdOrFPSSBKidFz9ySn6RUteXnKwc,5324
|
|
25
|
+
objectionengine2-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Luis Mayo Valbuena
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|