Skip to content

Commit

Permalink
feat: now loading multiple vania rooms at a time!
Browse files Browse the repository at this point in the history
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....
  • Loading branch information
russmatney committed May 25, 2024
1 parent e567c32 commit 39a3b05
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/components/quick_select/QuickSelectMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 13 additions & 3 deletions src/dino/modes/vania/Vania.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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")]([])
Expand Down
30 changes: 14 additions & 16 deletions src/dino/vania/VaniaGame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -280,7 +275,7 @@ func load_initial_room():

var def = rooms[0]

_load_room(def)
load_room(def)

## start_vania_game

Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand Down
17 changes: 8 additions & 9 deletions src/dino/vania/VaniaRoomTransitions.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class_name VaniaRoomTransitions

## vars ##################################

var PLAYER_POS_OFFSET = 40
var PLAYER_POS_OFFSET = 0
var game: VaniaGame

## init ##################################
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 39a3b05

Please sign in to comment.