Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SR editor, MEDS changes, Dependencies #211

Merged
merged 4 commits into from
Sep 16, 2023
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
15 changes: 8 additions & 7 deletions dread_editor/bmsad_editor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import construct
import imgui
from mercury_engine_data_structures import type_lib
from mercury_engine_data_structures.type_lib import get_type_lib_dread
from mercury_engine_data_structures.file_tree_editor import FileTreeEditor
from mercury_engine_data_structures.formats import Bmsad
from mercury_engine_data_structures.formats.bmsad import find_charclass_for_type
Expand All @@ -9,13 +9,14 @@
from dread_editor.file_editor import FileEditor
from dread_editor.type_render import TypeTreeRender

bmsad_tree_render = TypeTreeRender()


# TODO: Implement it for SR if we support it
class BmsadEditor(FileEditor):
def __init__(self, bmsad: Bmsad):
self.bmsad = bmsad
self.string_vector = type_lib.get_type("base::global::CRntVector<base::global::CStrId>")
self.type_lib = get_type_lib_dread()
self.bmsad_tree_render = TypeTreeRender(self.type_lib)
self.string_vector = self.type_lib.get_type("base::global::CRntVector<base::global::CStrId>")

def is_modified(self):
return False
Expand Down Expand Up @@ -48,7 +49,7 @@ def draw(self, current_scale: float):
imgui.next_column()
imgui.next_column()
if node_open:
changed, new_field = bmsad_tree_render.render_value_of_type(prop.sub_actors, self.string_vector,
changed, new_field = self.bmsad_tree_render.render_value_of_type(prop.sub_actors, self.string_vector,
"sub_actors")
if changed:
prop.sub_actors = new_field
Expand All @@ -66,9 +67,9 @@ def draw(self, current_scale: float):
# Fields
if component.fields is not None and imgui_util.tree_node_with_column(
f"Fields ##{component_key}_fields", imgui.TREE_NODE_DEFAULT_OPEN):
changed, new_field = bmsad_tree_render.render_value_of_type(
changed, new_field = self.bmsad_tree_render.render_value_of_type(
component.fields.fields,
type_lib.get_type(find_charclass_for_type(component.type)),
self.type_lib.get_type(find_charclass_for_type(component.type)),
f"{component_key}"
)
if changed:
Expand Down
27 changes: 18 additions & 9 deletions dread_editor/file_browser.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
import typing

import imgui
from mercury_engine_data_structures import type_lib
from mercury_engine_data_structures.file_tree_editor import FileTreeEditor
from mercury_engine_data_structures.type_lib import get_type_lib_dread
from mercury_engine_data_structures.file_tree_editor import FileTreeEditor, Game
from mercury_engine_data_structures.formats import Bmsad

from dread_editor.bmsad_editor import BmsadEditor
from dread_editor.file_editor import FileEditor, GenericEditor
from dread_editor.type_render import TypeTreeRender

tree_render = TypeTreeRender()


def create_editor_reader(type_name: str):
type_data = type_lib.get_type(type_name)
type_lib = get_type_lib_dread()
type_data = type_lib.get_type( type_name)
return lambda path, tree_editor: GenericEditor(
tree_editor.get_parsed_asset(path),
tree_render,
TypeTreeRender(type_lib),
type_data,
)


file_types = {
file_types_dread = {
".bmsad": lambda path, tree_editor: BmsadEditor(tree_editor.get_parsed_asset(path, type_hint=Bmsad)),
".bmmap": create_editor_reader('CMinimapData'),
".bmscu": create_editor_reader('CCutSceneDef'),
".brsa": create_editor_reader("gameeditor::CGameModelRoot"),
}

file_types_sr = {
".bmsad": lambda path, tree_editor: BmsadEditor(tree_editor.get_parsed_asset(path, type_hint=Bmsad)),
}

file_types = {
Game.SAMUS_RETURNS: file_types_sr,
Game.DREAD: file_types_dread
}


class FileBrowser:
_is_open: bool = False
filter: str = ""

def __init__(self, tree_editor: FileTreeEditor):
def __init__(self, tree_editor: FileTreeEditor, game: Game):
self.tree_editor = tree_editor
self.all_files_tree = {}
self.game = game

for asset_name in sorted(tree_editor.all_asset_names()):
name_tree = asset_name.split("/")
Expand Down Expand Up @@ -96,7 +105,7 @@ def draw_tree(parent_path: str, body: dict[str, typing.Any]):
full_path.parent.mkdir(parents=True, exist_ok=True)
full_path.write_bytes(self.tree_editor.get_raw_asset(full_name))

for extension, build in file_types.items():
for extension, build in file_types.get(self.game).items():
if name.endswith(extension):
if imgui.button("Open"):
open_editors[full_name] = build(full_name, self.tree_editor)
Expand Down
32 changes: 32 additions & 0 deletions dread_editor/level_data_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import typing
import imgui

from dread_editor.type_render import SpecificTypeRender
from dread_editor import imgui_util
from mercury_engine_data_structures.type_lib import BaseType

class LevelData:
def open_actor_link(self, link: str):
raise NotImplementedError("Not implemented")


class GameLinkRender(SpecificTypeRender):
def __init__(self, level_data: LevelData):
self.level_data = level_data

def uses_one_column(self, type_data: BaseType):
return True

def create_default(self, type_data: BaseType):
return "<EMPTY>"

def render_value(self, value: typing.Any, type_data: BaseType, path: str):
if isinstance(value, str) and value.startswith("Root"):
if imgui.button(value):
self.level_data.open_actor_link(value)
imgui_util.set_hovered_tooltip(value)
else:
imgui.text(str(value))
return False, None


39 changes: 11 additions & 28 deletions dread_editor/level_data.py → dread_editor/level_data_dread.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import typing

import imgui
from mercury_engine_data_structures import type_lib
from mercury_engine_data_structures.file_tree_editor import FileTreeEditor
from mercury_engine_data_structures.type_lib import get_type_lib_dread
from mercury_engine_data_structures.file_tree_editor import FileTreeEditor, Game
from mercury_engine_data_structures.formats import Brsa, Brfld, Bmscc
from mercury_engine_data_structures.formats.dread_types import CActor
from mercury_engine_data_structures.type_lib import BaseType

from dread_editor import imgui_util
from dread_editor.actor_filter import ActorFilter
from dread_editor.level_data_common import GameLinkRender, LevelData
from dread_editor.preferences import global_preferences, save_preferences
from dread_editor.type_render import TypeTreeRender, SpecificTypeRender

Expand All @@ -31,7 +32,7 @@ def get_subareas(pkg_editor: FileTreeEditor, brfld_path: str) -> set[str]:
return cams


class LevelData:
class LevelDataDread(LevelData):
def __init__(self, file_name: str, brfld: Brfld, bmscc: Bmscc, valid_cameras: dict[str, bool],
display_borders: dict[str, float]):

Expand All @@ -48,8 +49,9 @@ def __init__(self, file_name: str, brfld: Brfld, bmscc: Bmscc, valid_cameras: di
self.highlighted_actors_in_canvas = []
self.actor_filter = ActorFilter()
self.copy_actor_name = ""
self.type_lib = get_type_lib_dread()

self.tree_render = TypeTreeRender()
self.tree_render = TypeTreeRender(self.type_lib)
for k in ["CGameLink<CActor>", "CGameLink<CEntity>"]:
self.tree_render.specific_renders[k] = GameLinkRender(self)

Expand Down Expand Up @@ -256,11 +258,11 @@ def lerp_y(y):
]
if highlighted_section == entry.name:
draw_list.add_polyline(raw_vertices, imgui.get_color_u32_rgba(0.2, 0.8, 1, 1.0),
closed=True,
flags=imgui.DRAW_CLOSED,
thickness=5)
else:
draw_list.add_polyline(raw_vertices, imgui.get_color_u32_rgba(0.2, 0.2, 1, 0.8),
closed=True,
flags=imgui.DRAW_CLOSED,
thickness=3)

self.highlighted_actors_in_canvas = []
Expand Down Expand Up @@ -326,7 +328,7 @@ def draw_visible_actors(self, current_scale: float):
actor = self.brfld.actors_for_layer(layer_name)[actor_name]
imgui.columns(2, "actor details")
self.tree_render.render_value_of_type(
actor, type_lib.get_type(actor["@type"]),
actor, self.type_lib.get_type(actor["@type"]),
f"{self.file_name}.{layer_name}.{actor_name}",
)
imgui.columns(1, "actor details")
Expand Down Expand Up @@ -356,28 +358,9 @@ def apply_changes_to(self, pkg_editor: FileTreeEditor):
# pkg_editor.ensure_present(pkg_name, bmsad)


class GameLinkRender(SpecificTypeRender):
def __init__(self, level_data: LevelData):
self.level_data = level_data

def uses_one_column(self, type_data: BaseType):
return True

def create_default(self, type_data: BaseType):
return "<EMPTY>"

def render_value(self, value: typing.Any, type_data: BaseType, path: str):
if isinstance(value, str) and value.startswith("Root"):
if imgui.button(value):
self.level_data.open_actor_link(value)
imgui_util.set_hovered_tooltip(value)
else:
imgui.text(str(value))
return False, None


class InnerValueRender(SpecificTypeRender):
def __init__(self, level_data: LevelData):
def __init__(self, level_data: LevelDataDread):
self.level_data = level_data
self.cache = {}

Expand All @@ -393,7 +376,7 @@ def render_value(self, value: bytes, type_data: BaseType, path: str):

result = value
changed, new_actor = self.level_data.tree_render.render_value_of_type(
self.cache[path], type_lib.get_type("CActor"),
self.cache[path], self.level_data.type_lib.get_type("CActor"),
f"{path}.actor",
)
if changed:
Expand Down
Loading