Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
[ext_resource type="TileSet" uid="uid://b8qnr0owsbhhn" path="res://tiles/exterior_floors.tres" id="5_717he"]
[ext_resource type="TileSet" uid="uid://do0ffypatd77h" path="res://tiles/bridges.tres" id="6_obhrw"]
[ext_resource type="TileSet" uid="uid://41pk6xbhypue" path="res://tiles/fence.tres" id="7_5lu30"]
[ext_resource type="Shader" uid="uid://dui35fhf12sp5" path="res://scenes/game_elements/fx/world_rewoven/components/world_rewoven.gdshader" id="7_mwlmc"]
[ext_resource type="PackedScene" uid="uid://iu2q66clupc6" path="res://scenes/game_elements/characters/player/player.tscn" id="8_2l846"]
[ext_resource type="Texture2D" uid="uid://drlsbgxh5e6vv" path="res://scenes/game_elements/fx/world_rewoven/components/fabric_texture.png" id="8_50s3p"]
[ext_resource type="Script" uid="uid://dpw8lcjx68p3o" path="res://scenes/game_elements/fx/world_rewoven/components/tile_map_mask_bounds.gd" id="8_ssbsc"]
[ext_resource type="SpriteFrames" uid="uid://cxjwwgm86d6it" path="res://scenes/game_elements/characters/components/sprite_frames/storyweaver_red.tres" id="9_powm1"]
[ext_resource type="PackedScene" uid="uid://dkpelgxwtvcxd" path="res://scenes/game_elements/props/hookable_box/hookable_box.tscn" id="11_b1u67"]
[ext_resource type="PackedScene" uid="uid://d37mebu7atru7" path="res://scenes/game_elements/characters/enemies/guard/guard.tscn" id="13_rna1f"]
Expand All @@ -21,6 +24,29 @@
[ext_resource type="Script" uid="uid://dnp0tjloec2d7" path="res://scenes/game_logic/stealth_game_logic.gd" id="20_rna1f"]
[ext_resource type="Script" uid="uid://c5jp8y8mpge4w" path="res://scenes/game_elements/props/toggleable_tile_map_layer/toggleable_tile_map_layer.gd" id="20_tbxxm"]

[sub_resource type="Gradient" id="Gradient_lq5qh"]
colors = PackedColorArray(1, 1, 1, 1, 0, 0, 0, 1)

[sub_resource type="GradientTexture2D" id="GradientTexture2D_au3ml"]
gradient = SubResource("Gradient_lq5qh")
fill_from = Vector2(0, 1)
fill_to = Vector2(0, 0)

[sub_resource type="ShaderMaterial" id="ShaderMaterial_5hkkv"]
shader = ExtResource("7_mwlmc")
shader_parameter/mask_texture = SubResource("GradientTexture2D_au3ml")
shader_parameter/mask_origin = Vector2(896, 128)
shader_parameter/mask_size = Vector2(128, 448)
shader_parameter/fabric_texture = ExtResource("8_50s3p")
shader_parameter/fabric_scale = 1.0
shader_parameter/progress = 1.0
shader_parameter/target_canvas_group = false
shader_parameter/smoothness = 0.250000011875
shader_parameter/burn_size = 0.250000011875
shader_parameter/burn_color = Color(1.353, 1.353, 0.777, 1)
shader_parameter/canvas_modulate = Color(0.481789, 0.48179, 0.481789, 1)
shader_parameter/gray_intensity = 0.0

[sub_resource type="Gradient" id="Gradient_5j6h7"]
interpolation_mode = 2
interpolation_color_space = 2
Expand Down Expand Up @@ -84,8 +110,15 @@ tile_map_data = PackedByteArray("AAACAAMAAAAAAAAAAAADAAMAAAABAAIAAAAEAAMAAAABAAI
tile_set = ExtResource("7_5lu30")

[node name="FenceDoor" type="TileMapLayer" parent="TileMapLayers" unique_id=1123335364]
material = SubResource("ShaderMaterial_5hkkv")
tile_map_data = PackedByteArray("AAAHAAQAAAADAAEAAAAHAAUAAAACAAEAAAAHAAYAAAADAAIAAAA=")
tile_set = ExtResource("7_5lu30")
script = ExtResource("20_tbxxm")

[node name="TileMapMaskBounds" type="Node" parent="TileMapLayers/FenceDoor" unique_id=1792441067 node_paths=PackedStringArray("canvas_item")]
script = ExtResource("8_ssbsc")
canvas_item = NodePath("..")
metadata/_custom_type_script = "uid://dpw8lcjx68p3o"

[node name="OnTheGround" type="Node2D" parent="." unique_id=888515986]
y_sort_enabled = true
Expand All @@ -107,7 +140,7 @@ constrain_layer = NodePath("../../TileMapLayers/Paths")

[node name="HookableLever" parent="OnTheGround" unique_id=653701664 node_paths=PackedStringArray("targets") instance=ExtResource("14_esoiq")]
position = Vector2(703, 448)
targets = [NodePath("../../ToggleableTileMapLayer")]
targets = [NodePath("../../TileMapLayers/FenceDoor")]

[node name="HookableNeedle" parent="OnTheGround" unique_id=1182662384 instance=ExtResource("15_bhn5g")]
position = Vector2(64, 96)
Expand Down Expand Up @@ -270,11 +303,6 @@ alert_others_sound_stream = ExtResource("18_obhrw")
position = Vector2(207, 349.042)
curve = SubResource("Curve2D_rna1f")

[node name="ToggleableTileMapLayer" type="Node2D" parent="." unique_id=374995496 node_paths=PackedStringArray("target")]
script = ExtResource("20_tbxxm")
target = NodePath("../TileMapLayers/FenceDoor")
metadata/_custom_type_script = "uid://c5jp8y8mpge4w"

[node name="ScreenOverlay" type="CanvasLayer" parent="." unique_id=789862376]

[node name="CanvasModulate" type="CanvasModulate" parent="." unique_id=1807394969]
Expand Down
2 changes: 2 additions & 0 deletions scenes/dev/grapple/grapple_gym_2/grapple_gym_2.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ extends Node2D
var zoom_tween: Tween

@onready var camera_2d: Camera2D = %Camera2D
@onready var bridges_unlocked: ToggleableTileMapLayer = %BridgesUnlocked


func _ready() -> void:
bridges_unlocked.initialize_with_value(false)
GameState.player.abilities_changed.connect(_on_abilities_changed)
_on_abilities_changed()

Expand Down
35 changes: 33 additions & 2 deletions scenes/dev/grapple/grapple_gym_2/grapple_gym_2.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
[ext_resource type="SpriteFrames" uid="uid://cfgahyntmtfgu" path="res://scenes/game_elements/props/powerup/components/powerup_thread.tres" id="4_xhlcu"]
[ext_resource type="PackedScene" uid="uid://evb46lm6ssu2" path="res://scenes/game_elements/props/hookable_pin/hookable_pin.tscn" id="5_t21wp"]
[ext_resource type="Script" uid="uid://c5jp8y8mpge4w" path="res://scenes/game_elements/props/toggleable_tile_map_layer/toggleable_tile_map_layer.gd" id="7_3w461"]
[ext_resource type="Shader" uid="uid://dui35fhf12sp5" path="res://scenes/game_elements/fx/world_rewoven/components/world_rewoven.gdshader" id="8_k57dq"]
[ext_resource type="Texture2D" uid="uid://drlsbgxh5e6vv" path="res://scenes/game_elements/fx/world_rewoven/components/fabric_texture.png" id="9_6pxnx"]
[ext_resource type="PackedScene" uid="uid://covsdqqsd6rsy" path="res://scenes/game_elements/props/sign/sign.tscn" id="9_ctt8w"]
[ext_resource type="Script" uid="uid://dpw8lcjx68p3o" path="res://scenes/game_elements/fx/world_rewoven/components/tile_map_mask_bounds.gd" id="10_woov4"]
[ext_resource type="PackedScene" uid="uid://dohb701lxbe5s" path="res://scenes/game_elements/props/hookable_needle/hookable_needle.tscn" id="14_5qe2l"]
[ext_resource type="PackedScene" uid="uid://cvtty6np3dcv4" path="res://scenes/game_elements/props/all_hooked/all_hooked.tscn" id="15_0xn1s"]
[ext_resource type="PackedScene" uid="uid://d0c4l7ev6ca3c" path="res://scenes/game_elements/props/spawn_point/spawn_point.tscn" id="15_qjdbk"]
Expand All @@ -27,6 +30,27 @@
[ext_resource type="PackedScene" uid="uid://cfvr32bp2achm" path="res://scenes/game_elements/props/decoration/rock/fabric_rock.tscn" id="24_j21no"]
[ext_resource type="PackedScene" uid="uid://dttyvh6kyru5y" path="res://scenes/game_elements/props/decoration/butterfly/butterfly.tscn" id="25_3a52b"]

[sub_resource type="Gradient" id="Gradient_wymun"]
colors = PackedColorArray(1, 1, 1, 1, 0, 0, 0, 1)

[sub_resource type="GradientTexture2D" id="GradientTexture2D_7vm8y"]
gradient = SubResource("Gradient_wymun")

[sub_resource type="ShaderMaterial" id="ShaderMaterial_kjrmi"]
shader = ExtResource("8_k57dq")
shader_parameter/mask_texture = SubResource("GradientTexture2D_7vm8y")
shader_parameter/mask_origin = Vector2(1024, -1344)
shader_parameter/mask_size = Vector2(576, 64)
shader_parameter/fabric_texture = ExtResource("9_6pxnx")
shader_parameter/fabric_scale = 1.0
shader_parameter/progress = 1.0
shader_parameter/target_canvas_group = false
shader_parameter/smoothness = 0.3230000153425
shader_parameter/burn_size = 0.3430000162925
shader_parameter/burn_color = Color(1.353, 1.353, 0.777, 1)
shader_parameter/canvas_modulate = Color(1, 1, 1, 1)
shader_parameter/gray_intensity = 0.0

[node name="GrappleGym2" type="Node2D" unique_id=129556927]
script = ExtResource("1_4arhg")

Expand Down Expand Up @@ -59,10 +83,17 @@ tile_map_data = PackedByteArray("AAALAAAAAwAAAAMAAAALAP//AwAAAAIAAAALAP7/AwAAAAI
tile_set = ExtResource("3_75dn2")

[node name="BridgesUnlocked" type="TileMapLayer" parent="TileMapLayers" unique_id=1341990576]
unique_name_in_owner = true
material = SubResource("ShaderMaterial_kjrmi")
tile_map_data = PackedByteArray("AAAQAOv/AwAAAAAAAAARAOv/AwABAAAAAAASAOv/AwABAAAAAAATAOv/AwABAAAAAAAUAOv/AwABAAAAAAAVAOv/AwABAAAAAAAWAOv/AwABAAAAAAAXAOv/AwABAAAAAAAYAOv/AwACAAAAAAA=")
enabled = false
tile_set = ExtResource("3_75dn2")
script = ExtResource("7_3w461")
invert = true

[node name="TileMapMaskBounds" type="Node" parent="TileMapLayers/BridgesUnlocked" unique_id=448833223 node_paths=PackedStringArray("canvas_item")]
script = ExtResource("10_woov4")
canvas_item = NodePath("..")
metadata/_custom_type_script = "uid://dpw8lcjx68p3o"

[node name="OnTheGround" type="Node2D" parent="." unique_id=1706163952]
y_sort_enabled = true
Expand Down Expand Up @@ -485,4 +516,4 @@ position = Vector2(1336, 48)
position = Vector2(-158, 1375)

[connection signal="all_hooked" from="OnTheGround/AllHooked" to="TileMapLayers/WaterUnlocked" method="set_toggled" binds= [false]]
[connection signal="all_hooked" from="OnTheGround/AllHooked" to="TileMapLayers/BridgesUnlocked" method="set_toggled" binds= [false]]
[connection signal="all_hooked" from="OnTheGround/AllHooked" to="TileMapLayers/BridgesUnlocked" method="set_toggled" binds= [true]]
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
[ext_resource type="TileSet" uid="uid://b8qnr0owsbhhn" path="res://tiles/exterior_floors.tres" id="5_o0gav"]
[ext_resource type="TileSet" uid="uid://do0ffypatd77h" path="res://tiles/bridges.tres" id="6_743bw"]
[ext_resource type="TileSet" uid="uid://41pk6xbhypue" path="res://tiles/fence.tres" id="7_thbog"]
[ext_resource type="Shader" uid="uid://dui35fhf12sp5" path="res://scenes/game_elements/fx/world_rewoven/components/world_rewoven.gdshader" id="8_4mh5g"]
[ext_resource type="PackedScene" uid="uid://iu2q66clupc6" path="res://scenes/game_elements/characters/player/player.tscn" id="8_d53c5"]
[ext_resource type="SpriteFrames" uid="uid://cxjwwgm86d6it" path="res://scenes/game_elements/characters/components/sprite_frames/storyweaver_red.tres" id="9_qo67l"]
[ext_resource type="Texture2D" uid="uid://drlsbgxh5e6vv" path="res://scenes/game_elements/fx/world_rewoven/components/fabric_texture.png" id="9_rxnop"]
[ext_resource type="PackedScene" uid="uid://dqo4d6mp4hwhi" path="res://scenes/game_elements/props/repellable_box/repellable_box.tscn" id="10_s3xwn"]
[ext_resource type="Script" uid="uid://dpw8lcjx68p3o" path="res://scenes/game_elements/fx/world_rewoven/components/tile_map_mask_bounds.gd" id="11_au3ml"]
[ext_resource type="PackedScene" uid="uid://w50y4sa4xay2" path="res://scenes/game_elements/props/repellable_ball/repellable_ball.tscn" id="11_uqwf7"]
[ext_resource type="PackedScene" uid="uid://cuu65vogubwxd" path="res://scenes/game_elements/props/repellable_lever/repellable_lever.tscn" id="12_576oi"]
[ext_resource type="PackedScene" uid="uid://crqjcicx0vdu" path="res://scenes/game_elements/props/decoration/bush/bush.tscn" id="13_rqpd2"]
Expand All @@ -18,6 +21,30 @@
[ext_resource type="PackedScene" uid="uid://cl06pid826dtg" path="res://scenes/game_elements/characters/player/components/player_repel.tscn" id="16_bya72"]
[ext_resource type="Script" uid="uid://c5jp8y8mpge4w" path="res://scenes/game_elements/props/toggleable_tile_map_layer/toggleable_tile_map_layer.gd" id="17_xwlxp"]

[sub_resource type="Gradient" id="Gradient_lq5qh"]
colors = PackedColorArray(1, 1, 1, 1, 0, 0, 0, 1)

[sub_resource type="GradientTexture2D" id="GradientTexture2D_au3ml"]
gradient = SubResource("Gradient_lq5qh")
fill = 1
fill_from = Vector2(0.5, 0.5)
fill_to = Vector2(0, 0)

[sub_resource type="ShaderMaterial" id="ShaderMaterial_fhnvg"]
shader = ExtResource("8_4mh5g")
shader_parameter/mask_texture = SubResource("GradientTexture2D_au3ml")
shader_parameter/mask_origin = Vector2(896, 192)
shader_parameter/mask_size = Vector2(128, 320)
shader_parameter/fabric_texture = ExtResource("9_rxnop")
shader_parameter/fabric_scale = 1.0
shader_parameter/progress = 0.5990000284525
shader_parameter/target_canvas_group = false
shader_parameter/smoothness = 1.0
shader_parameter/burn_size = 1.0
shader_parameter/burn_color = Color(1.353, 1.353, 0.777, 1)
shader_parameter/canvas_modulate = Color(1, 1, 1, 1)
shader_parameter/gray_intensity = 0.0

[node name="CustomRepellableObjectsTest" type="Node2D" unique_id=324172432]
script = ExtResource("1_hfxxd")

Expand Down Expand Up @@ -50,12 +77,18 @@ tile_map_data = PackedByteArray("AAAGAAkAAwAAAAEAAAAGAAoAAwAAAAIAAAAGAAsAAwAAAAI
tile_set = ExtResource("6_743bw")

[node name="Fence" type="TileMapLayer" parent="TileMapLayers" unique_id=1482788515]
tile_map_data = PackedByteArray("AAAPAAcAAAACAAEAAAASAAcAAAAAAAEAAAASAAYAAAAAAAEAAAASAAUAAAACAAEAAAASAAQAAAACAAEAAAASAAMAAAACAAEAAAAPAAMAAAAAAAEAAAAPAAIAAAAAAAAAAAAQAAIAAAABAAAAAAARAAIAAAABAAAAAAASAAIAAAACAAAAAAAPAAgAAAAAAAIAAAAQAAgAAAABAAIAAAARAAgAAAABAAIAAAASAAgAAAACAAIAAAAPAAQAAAADAAIAAAAPAAYAAAADAAEAAAA=")
tile_map_data = PackedByteArray("AAAPAAcAAAADAAEAAAASAAcAAAAAAAEAAAASAAYAAAAAAAEAAAASAAUAAAACAAEAAAASAAQAAAACAAEAAAASAAMAAAACAAEAAAAPAAMAAAADAAIAAAAPAAIAAAAAAAAAAAAQAAIAAAABAAAAAAARAAIAAAABAAAAAAASAAIAAAACAAAAAAAPAAgAAAAAAAIAAAAQAAgAAAABAAIAAAARAAgAAAABAAIAAAASAAgAAAACAAIAAAA=")
tile_set = ExtResource("7_thbog")

[node name="FenceDoor" type="TileMapLayer" parent="TileMapLayers" unique_id=1123335364]
tile_map_data = PackedByteArray("AAAPAAQAAAAEAAAAAAAOAAQAAAAAAAAAAAAOAAYAAAAAAAIAAAAPAAYAAAAEAAAAAAAOAAUAAAAAAAEAAAA=")
[node name="FenceDoorClosed" type="TileMapLayer" parent="TileMapLayers" unique_id=1123335364]
material = SubResource("ShaderMaterial_fhnvg")
tile_map_data = PackedByteArray("AAAOAAQAAAACAAEAAAAOAAYAAAAAAAEAAAAOAAUAAAAAAAEAAAAOAAMAAAAAAAAAAAAPAAMAAAAEAAAAAAAOAAcAAAAAAAIAAAAPAAcAAAAEAAAAAAA=")
tile_set = ExtResource("7_thbog")
script = ExtResource("17_xwlxp")

[node name="TileMapMaskBounds" type="Node" parent="TileMapLayers/FenceDoorClosed" unique_id=203908000 node_paths=PackedStringArray("canvas_item")]
script = ExtResource("11_au3ml")
canvas_item = NodePath("..")

[node name="OnTheGround" type="Node2D" parent="." unique_id=888515986]
y_sort_enabled = true
Expand Down Expand Up @@ -100,7 +133,7 @@ position = Vector2(512, 1088)

[node name="RepellableLever" parent="OnTheGround" unique_id=37452001 node_paths=PackedStringArray("targets") instance=ExtResource("12_576oi")]
position = Vector2(726, 107)
targets = [NodePath("../../ToggleableTileMapLayer")]
targets = [NodePath("../../TileMapLayers/FenceDoorClosed")]

[node name="RepellableLever2" parent="OnTheGround" unique_id=632125149 instance=ExtResource("12_576oi")]
position = Vector2(1090, 614)
Expand Down Expand Up @@ -176,11 +209,6 @@ player_controlled = false
unique_name_in_owner = true
wait_time = 1.5

[node name="ToggleableTileMapLayer" type="Node2D" parent="." unique_id=374995496 node_paths=PackedStringArray("target")]
script = ExtResource("17_xwlxp")
target = NodePath("../TileMapLayers/FenceDoor")
metadata/_custom_type_script = "uid://c5jp8y8mpge4w"

[node name="ScreenOverlay" type="CanvasLayer" parent="." unique_id=789862376]

[connection signal="toggled" from="OnTheGround/RepellableLever2" to="." method="_on_repellable_lever_2_toggled"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# SPDX-FileCopyrightText: The Threadbare Authors
# SPDX-License-Identifier: MPL-2.0
@tool
class_name TileMapMaskBounds
extends BaseCanvasItemBehavior
## Feeds the bounds of a set of [TileMapLayer]s to a mask shader.
##
## Shaders such as world_rewoven.gdshader stretch a mask texture across a rect
## given in world units, so that it spans the affected area exactly once whether
## the material is applied to a [CanvasGroup] or to a single [CanvasItem]. This
## node computes that rect from the tiles that are in use, and writes it into the
## [code]mask_origin[/code] and [code]mask_size[/code] parameters of the
## [ShaderMaterial] of [member BaseCanvasItemBehavior.canvas_item].
## [br][br]
## Only [TileMapLayer]s are measured: the canvas item itself if it is one, plus
## every [TileMapLayer] among its descendants. A [Sprite2D], or any other kind of
## [CanvasItem], is ignored, because Godot has no general way to ask a canvas
## item for its bounds. So a [CanvasGroup] that mixes tile layers with other
## nodes gets a rect that covers the tile layers only, and one with no tile layer
## at all gets no rect, leaving the shader parameters untouched.
## [br][br]
## Add it as a child of the node holding the material. If [member
## BaseCanvasItemBehavior.canvas_item] is not set, the parent is used.

const MASK_ORIGIN := &"mask_origin"
const MASK_SIZE := &"mask_size"

## Recompute the rect. Useful after changing the tiles.
@export_tool_button("Update bounds") var update_button: Callable = update_bounds


func _set_canvas_item(new_canvas_item: CanvasItem) -> void:
super(new_canvas_item)
update_bounds()


func _ready() -> void:
update_bounds()


func _get_configuration_warnings() -> PackedStringArray:
var warnings := super()
if canvas_item:
if canvas_item.material is not ShaderMaterial:
warnings.push_back("Canvas item does not have a ShaderMaterial.")
elif _collect_layers(canvas_item).is_empty():
warnings.push_back(
"No TileMapLayer found in the canvas item, so bounds cannot be computed."
)
return warnings


## Computes the world-space bounds of the canvas item's tiles and writes them to
## its material.
func update_bounds() -> void:
if not is_inside_tree() or not canvas_item:
return

var material := canvas_item.material as ShaderMaterial
if not material:
return

var bounds := get_world_bounds(canvas_item)
if not bounds.has_area():
return

material.set_shader_parameter(MASK_ORIGIN, bounds.position)
material.set_shader_parameter(MASK_SIZE, bounds.size)


## Returns the bounds, in world units, of every [TileMapLayer] in [param root],
## including itself. Returns an empty [Rect2] when there is none.
static func get_world_bounds(root: CanvasItem) -> Rect2:
var bounds := Rect2()
var first := true

for layer: TileMapLayer in _collect_layers(root):
if not layer.tile_set:
continue
var used := layer.get_used_rect()
if not used.has_area():
continue

# get_used_rect() is in tile coordinates; convert to the layer's local
# pixels, then to world space so the rect is comparable across layers.
var tile_size := Vector2(layer.tile_set.tile_size)
var local := Rect2(Vector2(used.position) * tile_size, Vector2(used.size) * tile_size)
var world := layer.get_global_transform() * local

if first:
bounds = world
first = false
else:
bounds = bounds.merge(world)

return bounds


static func _collect_layers(node: Node) -> Array[TileMapLayer]:
var layers: Array[TileMapLayer] = []
if node is TileMapLayer:
layers.append(node as TileMapLayer)
for child: Node in node.get_children():
layers.append_array(_collect_layers(child))
return layers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dpw8lcjx68p3o
Loading
Loading