关卡重置逻辑

This commit is contained in:
RedisTKey 2026-01-14 19:39:23 +08:00
parent 94bcf60a6d
commit 744a9010d6
19 changed files with 141 additions and 12 deletions

View File

@ -1,8 +1,8 @@
extends Node2D extends Node2D
func _ready() -> void: func _ready() -> void:
$L0_S0.switch_act_by_id(1) #$L0_S0.switch_act_by_id(1)
#$L1_S1.switch_act_by_id(1) $L1_S1.switch_act_by_id(1)
#$L1_S2.switch_act_by_id(1) #$L1_S2.switch_act_by_id(1)
#$L1_S3.switch_act_by_id(1) #$L1_S3.switch_act_by_id(1)
#$L1_S4.switch_act_by_id(1) #$L1_S4.switch_act_by_id(1)

View File

@ -137,3 +137,11 @@ func start_move() -> void:
_path_follow.progress = 0.0 _path_follow.progress = 0.0
_current_speed = 0.0 _current_speed = 0.0
change_state(State.MOVING) change_state(State.MOVING)
func scene_reset() -> void:
if not path2d or not path2d.curve or not plateform:
return
var init_pos:= path2d.curve.get_point_position(0)
plateform.position = init_pos
change_state(State.IDLE)

View File

@ -0,0 +1,11 @@
extends Node
@export var reset_targets : Array[NodePath]
const RESET_INTERFACE_NAME := "scene_reset"
func reset_all() -> void:
for i in reset_targets:
var t := get_node_or_null(i)
if t and t.has_method("scene_reset"):
t.scene_reset()

View File

@ -0,0 +1 @@
uid://c8qho5tujjdtm

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dwrkfo2vhummq"]
[ext_resource type="Script" uid="uid://c8qho5tujjdtm" path="res://_scene/feature/Feature_Reset.gd" id="1_oyv48"]
[node name="[Featrue]reset" type="Node"]
script = ExtResource("1_oyv48")

View File

@ -1,6 +1,6 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://c7gm32jjs8wop"] [gd_resource type="Resource" load_steps=2 format=3 uid="uid://c7gm32jjs8wop"]
[ext_resource type="Script" uid="uid://dhs40v68rpfxr" path="res://_scene/guard/ActIDChanged/Guard_ActIDChangedCheck.gd" id="1_ae5sw"] [ext_resource type="Script" uid="uid://dhs40v68rpfxr" path="res://_scene/guard/Guard_ActIDChangedCheck.gd" id="1_ae5sw"]
[resource] [resource]
script = ExtResource("1_ae5sw") script = ExtResource("1_ae5sw")

View File

@ -1,11 +1,14 @@
extends SceneGuard '''
ActIDChanged绑定ActManager返回的ActChanged Signal
'''
class_name SG_ActIDChangedCheck extends SceneGuard
##如果为-1则不检查from_id只检查to id ##如果为-1则不检查from_id只检查to id
@export var from_id: int = -1 @export var from_id: int = -1
##如果为-1不检查如果不为-1则如果act manager的act changed的to act是此id此guard通过。 ##如果为-1不检查如果不为-1则如果act manager的act changed的to act是此id此guard通过。
@export var to_id: int = -1 @export var to_id: int = -1
func check(signal_args: Array) -> bool: func check(signal_args: Array, manager: SceneManager) -> bool:
if to_id < 0: if to_id < 0:
return true return true

View File

@ -0,0 +1,21 @@
'''
scene的idid和目标id匹配
'''
class_name SG_CurrentIDCheck extends SceneGuard
##在此列表里的id如果当被监听的signal触发时我们当前scene的id属于此id则会通过check否则不通过
@export var check_pass_ids: Array[int] = [-1]
func check(signal_args: Array, manager: SceneManager) -> bool:
if not manager:
return false
var am := manager._act_manager
if not am:
return false
for id in check_pass_ids:
if am._current_act_id == id and id >= 0:
return true
return false

View File

@ -0,0 +1 @@
uid://bhtwi61ts62ta

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=45 format=4 uid="uid://djs1eg5y008cs"] [gd_scene load_steps=58 format=4 uid="uid://djs1eg5y008cs"]
[ext_resource type="Script" uid="uid://5e157vdk6175" path="res://addons/reedscene/scene/ReedScene.gd" id="1_32vl4"] [ext_resource type="Script" uid="uid://5e157vdk6175" path="res://addons/reedscene/scene/ReedScene.gd" id="1_32vl4"]
[ext_resource type="PackedScene" uid="uid://dwrkfo2vhummq" path="res://_scene/feature/[Featrue]Reset.tscn" id="2_nnp13"]
[ext_resource type="Script" uid="uid://bh066o84byplh" path="res://addons/reedscene/scene/ReedSceneID.gd" id="2_of0lw"] [ext_resource type="Script" uid="uid://bh066o84byplh" path="res://addons/reedscene/scene/ReedSceneID.gd" id="2_of0lw"]
[ext_resource type="Script" uid="uid://dn0ksjoswquf5" path="res://addons/reedscene/scene/SceneManager.gd" id="3_32vl4"] [ext_resource type="Script" uid="uid://dn0ksjoswquf5" path="res://addons/reedscene/scene/SceneManager.gd" id="3_32vl4"]
[ext_resource type="Script" uid="uid://dsgl7lbyjsiif" path="res://addons/reedscene/act/ActManager.gd" id="4_10cyl"] [ext_resource type="Script" uid="uid://dsgl7lbyjsiif" path="res://addons/reedscene/act/ActManager.gd" id="4_10cyl"]
@ -8,10 +9,16 @@
[ext_resource type="Script" uid="uid://fxpk2ot6otfh" path="res://addons/reedscene/act/Act.gd" id="5_0xms0"] [ext_resource type="Script" uid="uid://fxpk2ot6otfh" path="res://addons/reedscene/act/Act.gd" id="5_0xms0"]
[ext_resource type="Resource" uid="uid://bym4pb0ellj7b" path="res://_scene/scene_trigger_resource/default_switch.tres" id="5_fdfto"] [ext_resource type="Resource" uid="uid://bym4pb0ellj7b" path="res://_scene/scene_trigger_resource/default_switch.tres" id="5_fdfto"]
[ext_resource type="Script" uid="uid://baqgorvlumyju" path="res://addons/reedscene/act/SingleAct.gd" id="6_agny0"] [ext_resource type="Script" uid="uid://baqgorvlumyju" path="res://addons/reedscene/act/SingleAct.gd" id="6_agny0"]
[ext_resource type="Script" uid="uid://bhtwi61ts62ta" path="res://_scene/guard/Guard_CurrentActCheck.gd" id="6_fmhh5"]
[ext_resource type="Script" uid="uid://dxj5vimigc651" path="res://addons/reedscene/scene/scene_trigger/base/SceneTriggerEffectPair.gd" id="6_uerbs"]
[ext_resource type="Script" uid="uid://pxjf5vst08eo" path="res://addons/reedscene/prop/PropManager.gd" id="7_8ou3l"] [ext_resource type="Script" uid="uid://pxjf5vst08eo" path="res://addons/reedscene/prop/PropManager.gd" id="7_8ou3l"]
[ext_resource type="Script" uid="uid://dq6xhoc441rfn" path="res://addons/reedscene/scene/scene_trigger/STR_Autoload.gd" id="7_w12cs"]
[ext_resource type="PackedScene" uid="uid://bflwr7cryd2l0" path="res://_camera/CameraAnchor.tscn" id="8_dq7pn"] [ext_resource type="PackedScene" uid="uid://bflwr7cryd2l0" path="res://_camera/CameraAnchor.tscn" id="8_dq7pn"]
[ext_resource type="Script" uid="uid://b1bgmb71bapws" path="res://addons/reedscene/scene/scene_trigger/base/SceneTriggerEffect.gd" id="8_qg43s"]
[ext_resource type="Script" uid="uid://b4menkyub4ce7" path="res://addons/reedscene/prop/PropComponent.gd" id="9_fdfto"] [ext_resource type="Script" uid="uid://b4menkyub4ce7" path="res://addons/reedscene/prop/PropComponent.gd" id="9_fdfto"]
[ext_resource type="Script" uid="uid://bjstkg23cq6vq" path="res://addons/reedscene/scene/scene_trigger/STE_SwitchAct.gd" id="10_4o7gt"]
[ext_resource type="Script" uid="uid://di41kt2tj34c2" path="res://addons/reedscene/prop/StateManager.gd" id="10_uerbs"] [ext_resource type="Script" uid="uid://di41kt2tj34c2" path="res://addons/reedscene/prop/StateManager.gd" id="10_uerbs"]
[ext_resource type="Script" uid="uid://5jmi0wcn1634" path="res://addons/reedscene/scene/scene_trigger/STT_NodePath.gd" id="11_tetem"]
[ext_resource type="Script" uid="uid://7lml6d1t5xtq" path="res://addons/reedscene/prop/PropState.gd" id="11_w12cs"] [ext_resource type="Script" uid="uid://7lml6d1t5xtq" path="res://addons/reedscene/prop/PropState.gd" id="11_w12cs"]
[ext_resource type="Script" uid="uid://cdvgq0xqdbagk" path="res://addons/reedscene/prop/Effect/ReedPropEffect.gd" id="12_fmhh5"] [ext_resource type="Script" uid="uid://cdvgq0xqdbagk" path="res://addons/reedscene/prop/Effect/ReedPropEffect.gd" id="12_fmhh5"]
[ext_resource type="Resource" uid="uid://bjjxh7g7iosla" path="res://_props/_camera/camera_anchor_disable.tres" id="13_qg43s"] [ext_resource type="Resource" uid="uid://bjjxh7g7iosla" path="res://_props/_camera/camera_anchor_disable.tres" id="13_qg43s"]
@ -27,6 +34,40 @@
[ext_resource type="PackedScene" uid="uid://csdxpv8gefpec" path="res://_props/_prefabs/plateform/movable_plateform.tscn" id="25_uerbs"] [ext_resource type="PackedScene" uid="uid://csdxpv8gefpec" path="res://_props/_prefabs/plateform/movable_plateform.tscn" id="25_uerbs"]
[ext_resource type="Texture2D" uid="uid://c673bap4b12fx" path="res://icon.svg" id="26_w12cs"] [ext_resource type="Texture2D" uid="uid://c673bap4b12fx" path="res://icon.svg" id="26_w12cs"]
[sub_resource type="Resource" id="Resource_qg43s"]
script = ExtResource("6_fmhh5")
check_pass_ids = Array[int]([1])
metadata/_custom_type_script = "uid://bhtwi61ts62ta"
[sub_resource type="Resource" id="Resource_bcboe"]
script = ExtResource("10_4o7gt")
func_name = &"reset_all"
metadata/_custom_type_script = "uid://bjstkg23cq6vq"
[sub_resource type="Resource" id="Resource_2un1l"]
script = ExtResource("11_tetem")
node_path = NodePath("../[Featrue]reset")
metadata/_custom_type_script = "uid://5jmi0wcn1634"
[sub_resource type="Resource" id="Resource_nnp13"]
script = ExtResource("6_uerbs")
target = SubResource("Resource_2un1l")
effect = Array[ExtResource("8_qg43s")]([SubResource("Resource_bcboe")])
metadata/_custom_type_script = "uid://dxj5vimigc651"
[sub_resource type="Resource" id="Resource_fmhh5"]
script = ExtResource("7_w12cs")
autoload_name = &"GlobalEvent"
monitor_signal = &"player_dead"
metadata/_custom_type_script = "uid://dq6xhoc441rfn"
[sub_resource type="Resource" id="Resource_w12cs"]
script = ExtResource("4_qrebp")
trigger_register_conifg = SubResource("Resource_fmhh5")
guard = SubResource("Resource_qg43s")
trigger_effect_pairs = Array[ExtResource("6_uerbs")]([SubResource("Resource_nnp13")])
metadata/_custom_type_script = "uid://ons77en82uls"
[sub_resource type="Resource" id="Resource_oupin"] [sub_resource type="Resource" id="Resource_oupin"]
script = ExtResource("6_agny0") script = ExtResource("6_agny0")
@ -115,12 +156,15 @@ point_count = 2
script = ExtResource("1_32vl4") script = ExtResource("1_32vl4")
metadata/_custom_type_script = "uid://5e157vdk6175" metadata/_custom_type_script = "uid://5e157vdk6175"
[node name="[Featrue]reset" parent="." instance=ExtResource("2_nnp13")]
reset_targets = Array[NodePath]([NodePath("../PathDriveMovePlateform")])
[node name="[Invalid!]" type="Node" parent="."] [node name="[Invalid!]" type="Node" parent="."]
script = ExtResource("2_of0lw") script = ExtResource("2_of0lw")
[node name="SceneManager" type="Node" parent="."] [node name="SceneManager" type="Node" parent="."]
script = ExtResource("3_32vl4") script = ExtResource("3_32vl4")
quick_trigger = Array[ExtResource("4_qrebp")]([ExtResource("5_fdfto")]) quick_trigger = Array[ExtResource("4_qrebp")]([ExtResource("5_fdfto"), SubResource("Resource_w12cs")])
[node name="ActManager" type="Node" parent="."] [node name="ActManager" type="Node" parent="."]
script = ExtResource("4_10cyl") script = ExtResource("4_10cyl")

View File

@ -1,6 +1,6 @@
[gd_resource type="TileSet" load_steps=3 format=3 uid="uid://cup1q1upvp18h"] [gd_resource type="TileSet" load_steps=3 format=3 uid="uid://cup1q1upvp18h"]
[ext_resource type="Texture2D" uid="uid://cew1x7g5aaa3j" path="res://_asset/ksw/basicTile.png" id="1_ln1fl"] [ext_resource type="Texture2D" uid="uid://7psxuet3jk1p" path="res://_asset/ksw/basicTile.png" id="1_ln1fl"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ln1fl"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ln1fl"]
texture = ExtResource("1_ln1fl") texture = ExtResource("1_ln1fl")

View File

@ -57,7 +57,7 @@ func _bind_quick_trigger() -> void:
## 当信号触发 ## 当信号触发
func _on_trigger_fired(trigger: SceneTrigger, signal_args: Array) -> void: func _on_trigger_fired(trigger: SceneTrigger, signal_args: Array) -> void:
if not trigger.can_trigger(signal_args): if not trigger.can_trigger(signal_args,self):
return return
for i in trigger.trigger_effect_pairs: for i in trigger.trigger_effect_pairs:
@ -74,5 +74,20 @@ func _on_trigger_fired(trigger: SceneTrigger, signal_args: Array) -> void:
var ex := j as SceneTriggerEffect var ex := j as SceneTriggerEffect
ex.apply_effect(t) ex.apply_effect(t)
## =============================
## External API
## =============================
func switch_act_with_id(id: int,trans_overwrite:int = 0) -> void: func switch_act_with_id(id: int,trans_overwrite:int = 0) -> void:
_act_manager.switch_act_with_id(id,trans_overwrite) _act_manager.switch_act_with_id(id,trans_overwrite)
## 外部快速获取Act Manager
func get_act_manager() -> ActManager:
return _act_manager
## 外部快速获取scene root
func get_scene_root() -> ReedScene:
return _scene if _scene else get_parent()
## 外部快速获取获取props映射
func get_props() -> Dictionary:
return _props

View File

@ -6,4 +6,4 @@ class_name SceneGuard
extends Resource extends Resource
@abstract @abstract
func check(signal_args: Array) -> bool func check(signal_args: Array, manager: SceneManager) -> bool

View File

@ -0,0 +1,6 @@
class_name STR_Autoload extends SceneTriggerRegister
@export var autoload_name: StringName
func get_register(owner: Object) -> Node:
return owner.get_tree().root.get_node_or_null("/root/%s" % autoload_name)

View File

@ -0,0 +1 @@
uid://dq6xhoc441rfn

View File

@ -0,0 +1,8 @@
class_name STT_NodePath extends SceneTriggerTarget
@export var node_path : NodePath
func get_effect_target(owner: Node) -> Object:
if owner:
return owner.get_node_or_null(node_path)
return null

View File

@ -0,0 +1 @@
uid://5jmi0wcn1634

View File

@ -9,7 +9,10 @@ class_name SceneTrigger extends Resource
var _owner: Node var _owner: Node
func can_trigger(args: Array) -> bool: func can_trigger(args: Array,scene_manager: SceneManager) -> bool:
if not guard.check(args): if not guard:
return true
if not guard.check(args, scene_manager):
return false return false
return true return true