about summary refs log tree commit diff stats
path: root/apworld/client/run_from_source.tscn
blob: 59a914d995af91c3f6796442fe427c3f94a571ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[gd_scene load_steps=11 format=2]

[sub_resource id=2 type="GDScript"]
script/source = "extends Node2D


func _ready():
	var args = OS.get_cmdline_user_args()
	var source_path = args[0]

	var runtime_script = ResourceLoader.load(\"%s/source_runtime.gd\" % source_path)
	var runtime = runtime_script.new(source_path)
	runtime.name = \"Runtime\"

	global.add_child(runtime)

	runtime.load_script_as_scene.call_deferred(\"settings_screen.gd\", \"settings_screen\")

"

[node name="loader" type="Node2D"]
script = SubResource( 2 )
ound-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
from typing import TYPE_CHECKING

from BaseClasses import Region, ItemClassification, Entrance
from .items import Lingo2Item
from .locations import Lingo2Location
from .player_logic import AccessRequirements
from .rules import make_location_lambda

if TYPE_CHECKING:
    from . import Lingo2World


def create_region(room, world: "Lingo2World") -> Region:
    new_region = Region(world.static_logic.get_room_region_name(room.id), world.player, world.multiworld)

    for location in world.player_logic.locations_by_room.get(room.id, {}):
        new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code],
                                      location.code, new_region)
        new_location.access_rule = make_location_lambda(location.reqs, world)
        new_region.locations.append(new_location)

    for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items():
        new_location = Lingo2Location(world.player, event_name, None, new_region)
        event_item = Lingo2Item(item_name, ItemClassification.progression, None, world.player)
        new_location.place_locked_item(event_item)
        new_region.locations.append(new_location)

    return new_region


def create_regions(world: "Lingo2World"):
    regions = {
        "Menu": Region("Menu", world.player, world.multiworld)
    }

    for room in world.static_logic.objects.rooms:
        region = create_region(room, world)
        regions[region.name] = region

    regions["Menu"].connect(regions["The Entry - Starting Room"], "Start Game")

    # TODO: The requirements of the opposite trigger also matter.
    for connection in world.static_logic.objects.connections:
        from_region = world.static_logic.get_room_region_name(connection.from_room)
        to_region = world.static_logic.get_room_region_name(connection.to_room)
        connection_name = f"{from_region} -> {to_region}"

        reqs = AccessRequirements()

        if connection.HasField("required_door"):
            reqs.merge(world.player_logic.get_door_open_reqs(connection.required_door))

            door = world.static_logic.objects.doors[connection.required_door]
            wmap = world.static_logic.objects.maps[door.map_id]
            connection_name = f"{connection_name} (using {wmap.name} - {door.name})"

        if connection.HasField("port"):
            port = world.static_logic.objects.ports[connection.port]
            connection_name = f"{connection_name} (via port {port.name})"

            if port.HasField("required_door"):
                reqs.merge(world.player_logic.get_door_open_reqs(port.required_door))

        if connection.HasField("painting"):
            painting = world.static_logic.objects.paintings[connection.painting]
            connection_name = f"{connection_name} (via painting {painting.name})"

            if painting.HasField("required_door"):
                reqs.merge(world.player_logic.get_door_open_reqs(painting.required_door))

        if connection.HasField("panel"):
            proxy = connection.panel
            reqs.merge(world.player_logic.get_panel_reqs(proxy.panel,
                                                         proxy.answer if proxy.HasField("answer") else None))

            panel = world.static_logic.objects.panels[proxy.panel]
            if proxy.HasField("answer"):
                connection_name = f"{connection_name} (via panel {panel.name}/{proxy.answer})"
            else:
                connection_name = f"{connection_name} (via panel {panel.name})"

        if from_region in regions and to_region in regions:
            connection = Entrance(world.player, connection_name, regions[from_region])
            connection.access_rule = make_location_lambda(reqs, world)

            regions[from_region].exits.append(connection)
            connection.connect(regions[to_region])

            for region in reqs.rooms:
                world.multiworld.register_indirect_condition(regions[region], connection)

    world.multiworld.regions += regions.values()