From 39a3b05626a1f1a0b4f8f8e1828b46efd97ab1fd Mon Sep 17 00:00:00 2001 From: Russell Matney Date: Sat, 25 May 2024 17:40:05 -0400 Subject: [PATCH] feat: now loading multiple vania rooms at a time! Some wonky behavior around lighting - vania rooms bring their own bg color and directional2D lights rn, so things start to clash, and shadows/tilemap occlusions seem to get offset strangely.... --- .../quick_select/QuickSelectMenu.gd | 2 +- src/dino/modes/vania/Vania.tscn | 16 ++++++++-- src/dino/vania/VaniaGame.gd | 30 +++++++++---------- src/dino/vania/VaniaRoomTransitions.gd | 17 +++++------ 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/components/quick_select/QuickSelectMenu.gd b/src/components/quick_select/QuickSelectMenu.gd index e997669b..9720d7e8 100644 --- a/src/components/quick_select/QuickSelectMenu.gd +++ b/src/components/quick_select/QuickSelectMenu.gd @@ -99,8 +99,8 @@ func show_menu(opts): screenBlur.fade_in({duration=anim_duration}) set_entities(opts.get("entities", entities), opts.get("on_select")) - set_focus() panel.set_visible(true) + set_focus.call_deferred() return selected diff --git a/src/dino/modes/vania/Vania.tscn b/src/dino/modes/vania/Vania.tscn index af58187d..05167424 100644 --- a/src/dino/modes/vania/Vania.tscn +++ b/src/dino/modes/vania/Vania.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://tfkeuag6o577"] +[gd_scene load_steps=13 format=3 uid="uid://tfkeuag6o577"] [ext_resource type="Script" path="res://src/dino/modes/vania/Vania.gd" id="1_w5rvh"] [ext_resource type="Script" path="res://src/dino/vania/RoomShape.gd" id="2_ysnxy"] @@ -10,15 +10,25 @@ script = ExtResource("2_ysnxy") cells = Array[Vector3i]([Vector3i(0, 0, 0)]) type = 1 +[sub_resource type="Resource" id="Resource_x6xdu"] +script = ExtResource("2_ysnxy") +cells = Array[Vector3i]([Vector3i(0, 0, 0), Vector3i(0, 1, 0), Vector3i(1, 1, 0)]) +type = 9 + +[sub_resource type="Resource" id="Resource_vbtpi"] +script = ExtResource("2_ysnxy") +cells = Array[Vector3i]([Vector3i(0, 0, 0), Vector3i(0, 1, 0), Vector3i(0, 2, 0)]) +type = 6 + [sub_resource type="Resource" id="Resource_10v7o"] script = ExtResource("3_tsuii") genre_type = 0 entities = Array[Resource("res://src/dino/entities/DinoEntity.gd")]([]) enemies = Array[Resource("res://src/dino/enemies/DinoEnemy.gd")]([]) -room_shapes = Array[ExtResource("2_ysnxy")]([SubResource("Resource_4hsaf")]) +room_shapes = Array[ExtResource("2_ysnxy")]([SubResource("Resource_4hsaf"), SubResource("Resource_x6xdu"), SubResource("Resource_vbtpi")]) room_effects = Array[Resource("res://src/dino/vania/RoomEffect.gd")]([]) tiles = Array[Resource("res://src/dino/tiles/DinoTiles.gd")]([]) -door_mode = 3 +door_mode = 1 neighbor_direction = Vector2i(0, 0) skip_borders = Array[Vector2i]([]) drops = Array[Resource("res://src/dino/pickups/DropData.gd")]([]) diff --git a/src/dino/vania/VaniaGame.gd b/src/dino/vania/VaniaGame.gd index 0211c784..f1301e65 100644 --- a/src/dino/vania/VaniaGame.gd +++ b/src/dino/vania/VaniaGame.gd @@ -133,15 +133,10 @@ func _ready(): func add_child_to_level(_node, child): if current_room and is_instance_valid(current_room): - Log.pr("adding child to current room", child, "current room position: ", current_room.position) current_room.add_child(child) else: add_child(child) -func on_room_quest_complete(_quest): - pass - # Log.pr("quest complete", quest) - func on_room_quests_complete(): mark_room_quests_complete() @@ -280,7 +275,7 @@ func load_initial_room(): var def = rooms[0] - _load_room(def) + load_room(def) ## start_vania_game @@ -461,11 +456,12 @@ func remove_room(count=1): ## load room ####################################################### -# overwriting metsys's Game.load_room to support 'setup' and setting a default layer -func _load_room(def: VaniaRoomDef, opts={}): +func load_room(def: VaniaRoomDef): + # look for an existing room var next_room = get_vania_room(def) if not next_room: + # load a new room next_room = load(def.room_path).instantiate() next_room.set_room_def(def) add_child(next_room) @@ -476,19 +472,21 @@ func _load_room(def: VaniaRoomDef, opts={}): Log.warn("No current room_instance, defaulting to layer 0") MetSys.current_layer = 0 - # not quite right, maybe gets eaten by run/quest manager? - mark_room_visited(def.room_path) + # store node for re-use if we re-enter + store_vania_room(next_room) - # make sure metsys knows this is the 'current' room - MetSys.current_room = next_room.room_instance - add_vania_room(next_room) room_loaded.emit() - if not next_room: - Log.warn("no next_room? wut?", next_room) + # make sure metsys knows this is the 'current' room!! + MetSys.current_room = next_room.room_instance + mark_room_visited(def.room_path) current_room = next_room + # TODO refactor into a single manager pre vania-game + var qm = current_room.quest_manager + qm.all_quests_complete.connect(on_room_quests_complete, CONNECT_ONE_SHOT) + func reload_current_room(): MetSys.room_changed.emit(MetSys.get_current_room_name(), false) @@ -536,7 +534,7 @@ func get_vania_room(def_or_path) -> VaniaRoom: return loaded_rooms.get(path) -func add_vania_room(room): +func store_vania_room(room): var path = room.room_def.room_path loaded_rooms[path] = room diff --git a/src/dino/vania/VaniaRoomTransitions.gd b/src/dino/vania/VaniaRoomTransitions.gd index 75984e9f..9c13efa0 100644 --- a/src/dino/vania/VaniaRoomTransitions.gd +++ b/src/dino/vania/VaniaRoomTransitions.gd @@ -3,7 +3,7 @@ class_name VaniaRoomTransitions ## vars ################################## -var PLAYER_POS_OFFSET = 40 +var PLAYER_POS_OFFSET = 0 var game: VaniaGame ## init ################################## @@ -32,11 +32,11 @@ func _on_room_changed(target_room: String, ignore_same_room=true): var prev_room_instance = MetSys.get_current_room_instance() - game._load_room(new_room_def) + game.load_room(new_room_def) - Log.info("%s rooms now loaded", len(game.get_vania_rooms())) # TODO at some n rooms, drop far-away rooms # maybe check for rooms that are n-cells away? + Log.info("%s rooms now loaded", len(game.get_vania_rooms())) var og_player = Dino.current_player_node() var og_p_position = og_player.position @@ -45,15 +45,14 @@ func _on_room_changed(target_room: String, ignore_same_room=true): var offset = Vector2() if prev_room_instance: offset = MetSys.get_current_room_instance().get_room_position_offset(prev_room_instance) - Log.pr("offset from prev!", offset) - # reposition all rooms according to the offset for room in game.get_vania_rooms(): if room.room_def.room_path == target_room: - continue - Log.pr("repositioning room", room.name, room.position) - room.position -= offset - Log.pr("repositioned room", room.name, room.position) + # the returned-to room needs a position reset + room.position = Vector2() + else: + # reposition other rooms according to the offset + room.position -= offset # maybe some nice way to handle this if abs(og_p_velocity.x) > abs(og_p_velocity.y):