mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 03:08:29 +02:00
added CTFileLayer (allow for patching a bmg file with the ctfile with all the tracks name)
This commit is contained in:
parent
47f191c9be
commit
8d30d1238a
5 changed files with 44 additions and 5 deletions
|
@ -90,7 +90,7 @@ class ExtractedGame:
|
|||
|
||||
# write ctfile data to a file in the cache
|
||||
ct_file = (cache_directory / "ctfile.lpar")
|
||||
ct_file.write_text(mod_config.get_ctfile())
|
||||
ct_file.write_text(mod_config.get_ctfile(template="-"))
|
||||
|
||||
# TODO: the lpar file should be customizable
|
||||
for lecode_file in (self.path / "files/rel/").glob("lecode-*.bin"):
|
||||
|
|
|
@ -165,9 +165,10 @@ class ModConfig:
|
|||
yield from self.get_ordered_cups()
|
||||
yield from self.get_unordered_cups()
|
||||
|
||||
def get_ctfile(self) -> str:
|
||||
def get_ctfile(self, template: str) -> str:
|
||||
"""
|
||||
Return the ct_file generated from the ModConfig
|
||||
:template: template for the track name
|
||||
:return: ctfile content
|
||||
"""
|
||||
lecode_flags = filter(lambda v: v is not None, [
|
||||
|
@ -187,7 +188,7 @@ class ModConfig:
|
|||
|
||||
for cup in self.get_cups():
|
||||
# get all the cup ctfile, use "-" for the template since the track's name are not used here
|
||||
ctfile += cup.get_ctfile(mod_config=self, template="-")
|
||||
ctfile += cup.get_ctfile(mod_config=self, template=template)
|
||||
|
||||
return ctfile
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
from source.mkw.Patch.PatchOperation.Operation.BmgTxtEditor.Layer import *
|
||||
from source.wt import ctc
|
||||
|
||||
Patch: any
|
||||
|
||||
|
||||
class CTFileLayer(AbstractLayer):
|
||||
"""
|
||||
Represent a layer that replace bmg entry by their ID
|
||||
"""
|
||||
|
||||
mode = "ctfile"
|
||||
|
||||
def __init__(self, template: dict[str, str]):
|
||||
self.template = template
|
||||
|
||||
def patch_bmg(self, patch: "Patch", decoded_content: str) -> str:
|
||||
return decoded_content + "\n" + (
|
||||
ctc.bmg_ctfile(patch.mod_config.get_ctfile(template=self.template))
|
||||
) + "\n"
|
||||
# add new bmg definition at the end of the bmg file, overwritting old id.
|
|
@ -11,5 +11,5 @@ class AbstractLayer(ABC):
|
|||
"""
|
||||
|
||||
|
||||
from source.mkw.Patch.PatchOperation.Operation.BmgTxtEditor.Layer import IDLayer, RegexLayer
|
||||
__all__ = ["AbstractLayer", "IDLayer", "RegexLayer"]
|
||||
from source.mkw.Patch.PatchOperation.Operation.BmgTxtEditor.Layer import IDLayer, RegexLayer, CTFileLayer
|
||||
__all__ = ["AbstractLayer", "IDLayer", "RegexLayer", "CTFileLayer"]
|
||||
|
|
17
source/wt/ctc.py
Normal file
17
source/wt/ctc.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from source.wt import *
|
||||
|
||||
tools_path = tools_szs_dir / "wctct"
|
||||
|
||||
|
||||
_tools_run = get_tools_run_function(tools_path)
|
||||
_tools_run_popen = get_tools_run_popen_function(tools_path)
|
||||
|
||||
|
||||
def bmg_ctfile(ctfile: "Path | str") -> str:
|
||||
|
||||
process = _tools_run_popen("BMG", "-", "--lecode")
|
||||
stdout, _ = process.communicate(input=ctfile.encode("utf-8"))
|
||||
if process.returncode != 0:
|
||||
raise WTError(tools_path, process.returncode)
|
||||
|
||||
return stdout.decode("utf-8")
|
Loading…
Reference in a new issue