Core: convert is_zip to zip_path
This commit is contained in:
parent
d0faa36eef
commit
a1aa9c17ff
4
Utils.py
4
Utils.py
|
@ -422,6 +422,10 @@ def get_text_between(text: str, start: str, end: str) -> str:
|
|||
return text[text.index(start) + len(start): text.rindex(end)]
|
||||
|
||||
|
||||
def get_text_after(text: str, start: str) -> str:
|
||||
return text[text.index(start) + len(start):]
|
||||
|
||||
|
||||
loglevel_mapping = {'error': logging.ERROR, 'info': logging.INFO, 'warning': logging.WARNING, 'debug': logging.DEBUG}
|
||||
|
||||
|
||||
|
|
|
@ -42,12 +42,11 @@ def get_app():
|
|||
def create_ordered_tutorials_file() -> typing.List[typing.Dict[str, typing.Any]]:
|
||||
import json
|
||||
import shutil
|
||||
import pathlib
|
||||
import zipfile
|
||||
|
||||
zfile: zipfile.ZipInfo
|
||||
|
||||
from worlds.AutoWorld import AutoWorldRegister, __file__
|
||||
from worlds.AutoWorld import AutoWorldRegister
|
||||
worlds = {}
|
||||
data = []
|
||||
for game, world in AutoWorldRegister.world_types.items():
|
||||
|
@ -60,8 +59,8 @@ def create_ordered_tutorials_file() -> typing.List[typing.Dict[str, typing.Any]]
|
|||
target_path = os.path.join(base_target_path, game)
|
||||
os.makedirs(target_path, exist_ok=True)
|
||||
|
||||
if world.is_zip:
|
||||
zipfile_path = pathlib.Path(world.__file__).parents[1]
|
||||
if world.zip_path:
|
||||
zipfile_path = world.zip_path
|
||||
|
||||
assert os.path.isfile(zipfile_path), f"{zipfile_path} is not a valid file(path)."
|
||||
assert zipfile.is_zipfile(zipfile_path), f"{zipfile_path} is not a valid zipfile."
|
||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import logging
|
||||
import sys
|
||||
import pathlib
|
||||
from typing import Dict, FrozenSet, Set, Tuple, List, Optional, TextIO, Any, Callable, Union, TYPE_CHECKING
|
||||
|
||||
from Options import Option
|
||||
|
@ -48,13 +49,14 @@ class AutoWorldRegister(type):
|
|||
raise RuntimeError(f"""Game {dct["game"]} already registered.""")
|
||||
AutoWorldRegister.world_types[dct["game"]] = new_class
|
||||
new_class.__file__ = sys.modules[new_class.__module__].__file__
|
||||
new_class.is_zip = ".apworld" in new_class.__file__
|
||||
if ".apworld" in new_class.__file__:
|
||||
new_class.zip_path = pathlib.Path(new_class.__file__).parents[1]
|
||||
return new_class
|
||||
|
||||
|
||||
class AutoLogicRegister(type):
|
||||
def __new__(cls, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> AutoLogicRegister:
|
||||
new_class = super().__new__(cls, name, bases, dct)
|
||||
def __new__(mcs, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> AutoLogicRegister:
|
||||
new_class = super().__new__(mcs, name, bases, dct)
|
||||
function: Callable[..., Any]
|
||||
for item_name, function in dct.items():
|
||||
if item_name == "copy_mixin":
|
||||
|
@ -179,7 +181,7 @@ class World(metaclass=AutoWorldRegister):
|
|||
item_names: Set[str] # set of all potential item names
|
||||
location_names: Set[str] # set of all potential location names
|
||||
|
||||
is_zip: bool # was loaded from a .apworld ?
|
||||
zip_path: Optional[pathlib.Path] = None # If loaded from a .apworld, this is the Path to it.
|
||||
__file__: str # path it was loaded from
|
||||
|
||||
def __init__(self, world: "MultiWorld", player: int):
|
||||
|
|
|
@ -37,7 +37,6 @@ for file in os.scandir(folder):
|
|||
world_sources.sort()
|
||||
for world_source in world_sources:
|
||||
if world_source.is_zip:
|
||||
|
||||
importer = zipimport.zipimporter(os.path.join(folder, world_source.path))
|
||||
importer.load_module(world_source.path.split(".", 1)[0])
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue