resolve merge conflict
This commit is contained in:
commit
4b82afa1ce
|
|
@ -0,0 +1,24 @@
|
||||||
|
[gd_scene load_steps=7 format=3 uid="uid://3vc8ojbiyy5w"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://crgac4manhoud" path="res://_game/game.gd" id="1_yksyv"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cvqehvdjpoar4" path="res://_player/player_controller.tscn" id="2_x2i0j"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://gwhff4qaouxy" path="res://_player/Avatar.tscn" id="3_4ifj7"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cd88ydqhdo28" path="res://_scene/level1/l1_s1.tscn" id="4_m1t3p"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://djs1eg5y008cs" path="res://_scene/level1/l1_s2.tscn" id="5_5s0xe"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dh43kt0l28qd5" path="res://_scene/level1/l1_s3.tscn" id="6_ktxjv"]
|
||||||
|
|
||||||
|
[node name="Game" type="Node2D"]
|
||||||
|
script = ExtResource("1_yksyv")
|
||||||
|
|
||||||
|
[node name="PlayerController" parent="." node_paths=PackedStringArray("auto_controlled_avatar") instance=ExtResource("2_x2i0j")]
|
||||||
|
auto_controlled_avatar = NodePath("../Avatar")
|
||||||
|
|
||||||
|
[node name="Avatar" parent="." instance=ExtResource("3_4ifj7")]
|
||||||
|
position = Vector2(-330, 0)
|
||||||
|
collision_mask = 4
|
||||||
|
|
||||||
|
[node name="L1_S1" parent="." instance=ExtResource("4_m1t3p")]
|
||||||
|
|
||||||
|
[node name="L1_S2" parent="." instance=ExtResource("5_5s0xe")]
|
||||||
|
|
||||||
|
[node name="L1_S3" parent="." instance=ExtResource("6_ktxjv")]
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://3vc8ojbiyy5w"]
|
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://crgac4manhoud" path="res://_game/game.gd" id="1_5cwyw"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cvqehvdjpoar4" path="res://_player/player_controller.tscn" id="2_4ake0"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://gwhff4qaouxy" path="res://_player/Avatar.tscn" id="3_vb6ml"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cd88ydqhdo28" path="res://_scene/level1/l1_s1.tscn" id="4_vb6ml"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://djs1eg5y008cs" path="res://_scene/level1/l1_s2.tscn" id="5_a1vfv"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://dh43kt0l28qd5" path="res://_scene/level1/l1_s3.tscn" id="6_w6pya"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://br46ftt4v3bwm" path="res://_scene/level1/l1_s4_Es.tscn" id="7_bmbbb"]
|
|
||||||
|
|
||||||
[node name="Game" type="Node2D"]
|
|
||||||
script = ExtResource("1_5cwyw")
|
|
||||||
|
|
||||||
[node name="PlayerController" parent="." node_paths=PackedStringArray("auto_controlled_avatar") instance=ExtResource("2_4ake0")]
|
|
||||||
auto_controlled_avatar = NodePath("../Avatar")
|
|
||||||
|
|
||||||
[node name="Avatar" parent="." instance=ExtResource("3_vb6ml")]
|
|
||||||
position = Vector2(1110.525, -400)
|
|
||||||
collision_mask = 4
|
|
||||||
|
|
||||||
[node name="L1_S1" parent="." instance=ExtResource("4_vb6ml")]
|
|
||||||
|
|
||||||
[node name="L1_S2" parent="." instance=ExtResource("5_a1vfv")]
|
|
||||||
|
|
||||||
[node name="L1_S3" parent="." instance=ExtResource("6_w6pya")]
|
|
||||||
|
|
||||||
[node name="L1_S4_Es" parent="." instance=ExtResource("7_bmbbb")]
|
|
||||||
|
|
@ -1,6 +1 @@
|
||||||
extends SceneManager
|
extends SceneManager
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_player_trigger_volumn_player_entered(body: CharacterBody2D) -> void:
|
|
||||||
_act_manager.switch_act_with_id(1)
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,11 @@
|
||||||
|
[gd_resource type="Resource" script_class="NodePathSceneTrigger" load_steps=3 format=3 uid="uid://gmaitie4ys4h"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://baamspwt4rm4r" path="res://addons/reedscene/scene/guard.gd" id="1_idvg7"]
|
||||||
|
[ext_resource type="Script" uid="uid://cvtkkcio4eeod" path="res://addons/reedscene/scene/NodePathSceneTrigger.gd" id="2_4sckh"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_4sckh")
|
||||||
|
path = NodePath("../Props/PlayerTriggerVolumn")
|
||||||
|
target_act_id = 1
|
||||||
|
monitor_signal = &"player_entered"
|
||||||
|
metadata/_custom_type_script = "uid://cvtkkcio4eeod"
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
[gd_resource type="Resource" script_class="PropIDSceneTrigger" load_steps=3 format=3 uid="uid://cstjpy2eh8mck"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://baamspwt4rm4r" path="res://addons/reedscene/scene/guard.gd" id="1_ugibh"]
|
||||||
|
[ext_resource type="Script" uid="uid://bprxx881tmhn8" path="res://addons/reedscene/scene/PropIDSceneTrigger.gd" id="2_501i5"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_501i5")
|
||||||
|
prop_id = 1
|
||||||
|
target_act_id = 1
|
||||||
|
monitor_signal = &"player_entered"
|
||||||
|
metadata/_custom_type_script = "uid://bprxx881tmhn8"
|
||||||
Binary file not shown.
|
|
@ -32,16 +32,19 @@ func _ready() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
##通过ID切换act
|
##通过ID切换act
|
||||||
func switch_act_with_id(act_id: int) -> void:
|
## 如果trans overwrite = 0,则使用act上自己配置的use trans
|
||||||
|
## 如果trans overwrite = 1,则全部禁用use trans
|
||||||
|
## 如果trans overwrite = 2,则全部开启use trans,注意,如果没有trans,则还是正常的切换
|
||||||
|
func switch_act_with_id(act_id: int,trans_overwrite: int = 0) -> void:
|
||||||
if not prop_state_map.has(act_id):
|
if not prop_state_map.has(act_id):
|
||||||
push_warning("[ActManager] Act id not found: %d" % act_id)
|
push_warning("[ActManager] Act id not found: %d" % act_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
var act := prop_state_map[act_id]
|
var act := prop_state_map[act_id]
|
||||||
_switch_act_internal(act, act_id)
|
_switch_act_internal(act, act_id,trans_overwrite)
|
||||||
|
|
||||||
##内部通过ID和Act来切换状态
|
##内部通过ID和Act来切换状态
|
||||||
func _switch_act_internal(act: Act, act_id: int) -> void:
|
func _switch_act_internal(act: Act, act_id: int, trans_overwrite: int = 0) -> void:
|
||||||
if act == null:
|
if act == null:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -59,7 +62,13 @@ func _switch_act_internal(act: Act, act_id: int) -> void:
|
||||||
if prop == null:
|
if prop == null:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
prop.change_state(single.state_id, single.use_trans)
|
var use_trans: bool = false
|
||||||
|
match trans_overwrite:
|
||||||
|
0: use_trans = single.use_trans
|
||||||
|
1: use_trans = false
|
||||||
|
2: use_trans = true
|
||||||
|
|
||||||
|
prop.change_state(single.state_id, use_trans)
|
||||||
|
|
||||||
emit_signal("act_changed", from_id, act_id)
|
emit_signal("act_changed", from_id, act_id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
class_name NodePathSceneTrigger extends SceneTrigger
|
||||||
|
|
||||||
|
@export var path: NodePath
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cvtkkcio4eeod
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
class_name PropIDSceneTrigger extends SceneTrigger
|
||||||
|
|
||||||
|
@export var prop_id: int
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bprxx881tmhn8
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
class_name SceneManager
|
class_name SceneManager
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
@export var quick_trigger: Array[SceneTrigger]
|
||||||
## ==============================
|
## ==============================
|
||||||
## References
|
## References
|
||||||
## ==============================
|
## ==============================
|
||||||
|
|
@ -8,9 +9,6 @@ var _scene: ReedScene
|
||||||
var _act_manager: ActManager
|
var _act_manager: ActManager
|
||||||
var _props: Dictionary # prop_id -> PropComponent
|
var _props: Dictionary # prop_id -> PropComponent
|
||||||
|
|
||||||
## ==============================
|
|
||||||
## Lifecycle
|
|
||||||
## ==============================
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
await get_parent().ready
|
await get_parent().ready
|
||||||
|
|
||||||
|
|
@ -20,11 +18,9 @@ func _ready() -> void:
|
||||||
return
|
return
|
||||||
|
|
||||||
_resolve_references()
|
_resolve_references()
|
||||||
_bind_signals()
|
|
||||||
|
|
||||||
## ==============================
|
_bind_quick_trigger()
|
||||||
## Resolve References
|
|
||||||
## ==============================
|
|
||||||
func _resolve_scene() -> void:
|
func _resolve_scene() -> void:
|
||||||
var p := get_parent()
|
var p := get_parent()
|
||||||
if p is ReedScene:
|
if p is ReedScene:
|
||||||
|
|
@ -33,36 +29,64 @@ func _resolve_scene() -> void:
|
||||||
_scene = null
|
_scene = null
|
||||||
|
|
||||||
func _resolve_references() -> void:
|
func _resolve_references() -> void:
|
||||||
# 从 ReedScene 拿“整理好的结果”
|
|
||||||
_act_manager = _scene._act_manager
|
_act_manager = _scene._act_manager
|
||||||
_props = _scene._prop_map
|
_props = _scene._prop_map
|
||||||
|
|
||||||
|
func _bind_quick_trigger() -> void:
|
||||||
|
for qt in quick_trigger:
|
||||||
|
if qt is PropIDSceneTrigger:
|
||||||
|
_bind_prop_id_trigger(qt)
|
||||||
|
elif qt is NodePathSceneTrigger:
|
||||||
|
_bind_node_path_trigger(qt)
|
||||||
|
|
||||||
## ==============================
|
## 通过Prop id来绑定signal
|
||||||
## Signal Binding
|
func _bind_prop_id_trigger(trigger: PropIDSceneTrigger) -> void:
|
||||||
## ==============================
|
var prop : Node = _props.get(trigger.prop_id).get_parent()
|
||||||
|
if prop == null:
|
||||||
|
return
|
||||||
|
|
||||||
func _bind_signals() -> void:
|
var s: StringName = trigger.monitor_signal
|
||||||
if _act_manager:
|
if not prop.has_signal(s):
|
||||||
_act_manager.act_changed.connect(_on_act_changed)
|
push_error("Prop has no signal: %s" % trigger.monitor_signal)
|
||||||
|
return
|
||||||
|
|
||||||
#for prop_id in _props:
|
prop.connect(
|
||||||
#var prop : PropComponent = _props[prop_id]
|
trigger.monitor_signal,
|
||||||
#_bind_prop_signals(prop)
|
func(...args):
|
||||||
#
|
_on_trigger_fired(trigger, args)
|
||||||
#func _bind_prop_signals(prop: PropComponent) -> void:
|
)
|
||||||
## 示例:监听 prop 的自定义信号
|
|
||||||
#if prop.has_signal("activated"):
|
|
||||||
#prop.activated.connect(func():
|
|
||||||
#_on_prop_activated(prop)
|
|
||||||
#)
|
|
||||||
|
|
||||||
|
## 通过NodePath来绑定signal
|
||||||
|
func _bind_node_path_trigger(trigger: NodePathSceneTrigger) -> void:
|
||||||
|
if trigger.path.is_empty():
|
||||||
|
return
|
||||||
|
|
||||||
## ==============================
|
var n : Node = self.get_node_or_null(trigger.path)
|
||||||
## Callbacks
|
|
||||||
## ==============================
|
if n == null:
|
||||||
func _on_act_changed(from_act: int, to_act: int) -> void:
|
return
|
||||||
print("[SceneManager] Act changed:", from_act, "->", to_act)
|
|
||||||
|
var s: StringName = trigger.monitor_signal
|
||||||
|
if not n.has_signal(s):
|
||||||
|
push_error("Prop has no signal: %s" % trigger.monitor_signal)
|
||||||
|
return
|
||||||
|
|
||||||
|
n.connect(
|
||||||
|
trigger.monitor_signal,
|
||||||
|
func(...args):
|
||||||
|
_on_trigger_fired(trigger, args)
|
||||||
|
)
|
||||||
|
|
||||||
|
## 当信号触发
|
||||||
|
func _on_trigger_fired(trigger: SceneTrigger, signal_args: Array) -> void:
|
||||||
|
if not trigger.can_trigger(signal_args):
|
||||||
|
return
|
||||||
|
|
||||||
|
var target_act_id: int = trigger.target_act_id
|
||||||
|
var trans_overwrite: int = trigger.trans_overwrite
|
||||||
|
|
||||||
|
if target_act_id < 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
_act_manager.switch_act_with_id(target_act_id,trans_overwrite)
|
||||||
|
|
||||||
func _on_prop_activated(prop: PropComponent) -> void:
|
|
||||||
print("[SceneManager] Prop activated:", prop.prop_id)
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
@abstract
|
||||||
|
class_name SceneTrigger extends Resource
|
||||||
|
|
||||||
|
@export var target_act_id: int
|
||||||
|
@export var monitor_signal: StringName
|
||||||
|
@export var guards: Array[SceneGuard]
|
||||||
|
@export var trans_overwrite: int = 0
|
||||||
|
|
||||||
|
func can_trigger(args: Array) -> bool:
|
||||||
|
for g in guards:
|
||||||
|
if not g.check(args):
|
||||||
|
return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://ons77en82uls
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
'''
|
||||||
|
配合SceneTrigger的Resource,必须在脚本内重写。
|
||||||
|
'''
|
||||||
|
@abstract
|
||||||
|
class_name SceneGuard
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
@abstract
|
||||||
|
func check(signal_args: Array) -> bool
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://baamspwt4rm4r
|
||||||
Loading…
Reference in New Issue