Core: expose world version to world classes and yaml (#5484)

* support version on new manifest

* apply world version from manifest

* Update Generate.py

* docs

* reduce mm2 version again

* wrong version

* validate game in world_types

* Update Generate.py

* let unknown game fall through to later exception

* hide real world version behind property

* named tuple is immutable

* write minimum world version to template yaml, fix gen edge cases

* punctuation

* check for world version in autoworldregister

* missed one

---------

Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com>
This commit is contained in:
Silvris
2025-09-30 19:47:08 -05:00
committed by GitHub
parent 4893ac3e51
commit 33b485c0c3
9 changed files with 69 additions and 10 deletions

View File

@@ -7,10 +7,11 @@ import warnings
import zipimport
import time
import dataclasses
import json
from typing import List
from NetUtils import DataPackage
from Utils import local_path, user_path, Version, version_tuple
from Utils import local_path, user_path, Version, version_tuple, tuplize_version
local_folder = os.path.dirname(__file__)
user_folder = user_path("worlds") if user_path() != local_path() else user_path("custom_worlds")
@@ -111,8 +112,25 @@ for world_source in world_sources:
else:
world_source.load()
from .AutoWorld import AutoWorldRegister
for world_source in world_sources:
if not world_source.is_zip:
# look for manifest
manifest = {}
for dirpath, dirnames, filenames in os.walk(world_source.resolved_path):
for file in filenames:
if file.endswith("archipelago.json"):
manifest = json.load(open(os.path.join(dirpath, file), "r"))
break
if manifest:
break
game = manifest.get("game")
if game in AutoWorldRegister.world_types:
AutoWorldRegister.world_types[game].world_version = Version(*tuplize_version(manifest.get("world_version",
"0.0.0")))
if apworlds:
# encapsulation for namespace / gc purposes
def load_apworlds() -> None:
@@ -164,6 +182,10 @@ if apworlds:
add_as_failed_to_load=False)
else:
apworld_source.load()
if apworld.game in AutoWorldRegister.world_types:
# world could fail to load at this point
if apworld.world_version:
AutoWorldRegister.world_types[apworld.game].world_version = apworld.world_version
load_apworlds()
del load_apworlds