from worlds.LauncherComponents import Component, SuffixIdentifier, components, Type, launch
from .locations import all_locations, Location, LocationData, OriginRegionName, set_up_rules
+from .util import load_resource
GAME = "SICPelago"
return ItemClassification.trap
return ItemClassification.filler
-with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'items.yml'), 'r') as input:
- all_items = {data['name']: ItemData(data) for data in yaml.safe_load(input)}
+
+all_items = {data['name']: ItemData(data) for data in yaml.safe_load(load_resource('items.yml'))}
class SicpWorld(World):
from NetUtils import ClientStatus
from . import all_items
+from .util import load_resource
from .game import game
from .game.scheme import buffer_input, scheme_read, scheme_eval, scheme_format, SchemeError
ctx.should_wait_for_events = True
async def game_loop(ctx: Context):
- game.setup()
+ game.setup(load_resource=lambda rsrc: load_resource(os.path.join('game', rsrc)))
unsent_checks = []
game.problem_solved_hook = lambda problem: unsent_checks.append(problem) or True
env = game.ThePlayerFrame
import BaseClasses
from worlds.generic.Rules import set_rule
+from .util import load_resource
+
GAME = "SICPelago"
OriginRegionName = "REPL"
(chapter, exercise) = str(self).split(' ')[0].split('.')
return int(chapter) * 100 + int(exercise)
-with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'locations.yml'), 'r') as input:
- all_locations = [LocationData(data) for data in yaml.safe_load(input)]
+all_locations = [LocationData(data) for data in yaml.safe_load(load_resource('locations.yml'))]
def set_up_rules(loc: LocationData, root: BaseClasses.Region, region: BaseClasses.Region, player: int):
__path__ = ["."]
from .scheme import *
+from .scheme_tokens import tokenize_lines
from .ucb import main
-from collections.abc import Iterable, Iterator
+from collections.abc import Callable, Iterable, Iterator
from typing import Any, Optional, Union
import itertools
if name not in exceptions and not name.startswith("#"):
frame.define(name, Locked(name))
-def load_problems(problems: dict[str, Problem], yaml_path: str):
- with open(yaml_path, 'r') as input:
- for problem_data in yaml.safe_load(input):
- problems[Problem.label_for(problem_data)] = Problem(problem_data)
+def load_problems(problems: dict[str, Problem], problem_yaml: bytes):
+ for problem_data in yaml.safe_load(problem_yaml):
+ problems[Problem.label_for(problem_data)] = Problem(problem_data)
def generate_problem_rewards_except(problems: Iterable[str], frame_of_locks: Frame, *exceptions: Symbol) -> dict[str, list[Union[Symbol, MacGuffin]]]:
rewards: dict[str, list[Union[Symbol, MacGuffin]]] = {}
Problems: dict[str, Problem] = {}
ProblemRewards: dict[str, Optional[list[Union[Symbol, MacGuffin]]]] = {}
-def setup() -> None:
+def default_load_resource(resource_name: str) -> bytes:
+ dirname = os.path.dirname(os.path.realpath(__file__))
+ with open(os.path.join(dirname, resource_name), 'rb') as rsrc:
+ return rsrc.read()
+
+def setup(load_resource: Optional[Callable[[str], bytes]] = None) -> None:
+ if not load_resource:
+ load_resource = default_load_resource
+
TheGlobalFrame.define('#undef', SpecialForm('#undef', do_undef))
- game_dir = os.path.dirname(os.path.realpath(__file__))
- prelude_path = os.path.join(game_dir, "game_prelude.scm")
- scheme_load(prelude_path, True, TheGlobalFrame)
+ prelude = str(load_resource('game_prelude.scm'), 'utf-8')
+ prelude_buf = Buffer(tokenize_lines(prelude.splitlines()))
+ while prelude_buf.current():
+ expr = scheme_read(prelude_buf)
+ scheme_eval(expr, TheGlobalFrame)
shadow_all_forms_except(TheLockingFrame, 'lambda', 'quote', 'display', 'print', 'newline', 'error')
- load_problems(Problems, os.path.join(game_dir, 'locations.yml'))
+ load_problems(Problems, load_resource('locations.yml'))
global ProblemRewards
ProblemRewards = generate_problem_rewards_except(Problems.keys(), TheLockingFrame, 'eval', 'exit', 'load')