Skip to content
Merged
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
16 changes: 11 additions & 5 deletions gm4/plugins/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Any, Optional

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

def write_updates(ctx: Context):
"""Writes the module update commands to this module's init function."""
init = ctx.data.functions.get(f"{ctx.project_id}:init", None)
if init is None:
for overlay in ctx.data.overlays.values():
write_update_function(overlay.functions.get(f"{ctx.project_id}:init"), ctx)
write_update_function(ctx.data.functions.get(f"{ctx.project_id}:init"), ctx)


def write_update_function(init: Optional[Function], ctx: Context):
if not init:
return

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

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}\"}}")

# Remove the marker if it exists
if "#$moduleUpdateList" in init.lines:
init.lines.remove("#$moduleUpdateList")
Expand All @@ -300,7 +305,8 @@ def write_updates(ctx: Context):
version = Version(m.version).int_rep()
website = f"https://gm4.co/modules/{m.id[4:].replace('_','-')}"
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'}}}}}}}}")



def repro_structure_to_bytes(content: StructureFileData) -> bytes:
"""a modified Structure.to_bytes from beet, which ensures the GZip does not add
the current time.time to the nbt file header.
Expand Down
Loading