Skip to content

Commit 22d6c6e

Browse files
runcowsmisode
andauthored
Update manifest.py to allow overlays of init functions (#1184)
* Update `manifest.py` to allow overlays of init functions * Refactor changes --------- Co-authored-by: Misode <[email protected]>
1 parent 4f7bbe9 commit 22d6c6e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

gm4/plugins/manifest.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import Any, Optional
1111

1212
import yaml
13-
from beet import Context, InvalidProjectConfig, PluginOptions, TextFile, load_config
13+
from beet import Context, InvalidProjectConfig, PluginOptions, TextFile, load_config, Function
1414
from beet.library.base import _dump_files # type: ignore ; private method used to deterministicify pack dumping
1515
from nbtlib.contrib.minecraft import StructureFileData, StructureFile # type: ignore ; no stub
1616
from pydantic.v1 import BaseModel, Extra
@@ -268,8 +268,13 @@ def write_credits(ctx: Context):
268268

269269
def write_updates(ctx: Context):
270270
"""Writes the module update commands to this module's init function."""
271-
init = ctx.data.functions.get(f"{ctx.project_id}:init", None)
272-
if init is None:
271+
for overlay in ctx.data.overlays.values():
272+
write_update_function(overlay.functions.get(f"{ctx.project_id}:init"), ctx)
273+
write_update_function(ctx.data.functions.get(f"{ctx.project_id}:init"), ctx)
274+
275+
276+
def write_update_function(init: Optional[Function], ctx: Context):
277+
if not init:
273278
return
274279

275280
manifest = ManifestCacheModel.parse_obj(ctx.cache["gm4_manifest"].json)
@@ -286,7 +291,7 @@ def write_updates(ctx: Context):
286291
last_i = i
287292

288293
init.lines.insert(last_i+1, f"data modify storage gm4:log versions append value {{id:\"{ctx.project_id}\",module:\"{ctx.project_name}\",version:\"{version}\"}}")
289-
294+
290295
# Remove the marker if it exists
291296
if "#$moduleUpdateList" in init.lines:
292297
init.lines.remove("#$moduleUpdateList")
@@ -300,7 +305,8 @@ def write_updates(ctx: Context):
300305
version = Version(m.version).int_rep()
301306
website = f"https://gm4.co/modules/{m.id[4:].replace('_','-')}"
302307
init.lines.append(f"execute if score {m.id} load.status matches -1.. if score {m.id.removeprefix('gm4_')} gm4_modules matches ..{version - 1} run data modify storage gm4:log queue append value {{type:'outdated',module:'{m.name}',download:'{website}',render:{{'text':'{m.name}','click_event':{{'action':'open_url','url':'{website}'}},'hover_event':{{'action':'show_text','value':{{'text':'Click to visit {website}','color':'#4AA0C7'}}}}}}}}")
303-
308+
309+
304310
def repro_structure_to_bytes(content: StructureFileData) -> bytes:
305311
"""a modified Structure.to_bytes from beet, which ensures the GZip does not add
306312
the current time.time to the nbt file header.

0 commit comments

Comments
 (0)