godot-mechanic-secrets
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSecrets & Easter Eggs (Mechanics)
秘籍与复活节彩蛋(机制)
Overview
概述
This skill provides reusable components for hiding content behind specific player actions (e.g., Konami code, repetitive interaction) and managing the persistence of these discoveries.
此Skill提供可复用组件,用于将内容隐藏在特定玩家操作(如科乐美代码、重复交互)之后,并管理这些发现内容的持久化状态。
Core Components
核心组件
1. Input Sequence Watcher (input_sequence_watcher.gd
)
input_sequence_watcher.gd1. Input Sequence Watcher (input_sequence_watcher.gd
)
input_sequence_watcher.gdA node that listens for a specific sequence of s.
InputEvent- Use for: Classic "Cheat Codes", hidden debug menus, "Konami Code" implementations.
- Behavior: Buffers input -> Checks against target -> Emits .
sequence_matched
一个监听特定序列的节点。
InputEvent- 用途:经典“作弊码”、隐藏调试菜单、“科乐美代码”实现。
- 行为:缓存输入 -> 与目标序列比对 -> 触发信号。
sequence_matched
2. Interaction Threshold Trigger (interaction_threshold_trigger.gd
)
interaction_threshold_trigger.gd2. Interaction Threshold Trigger (interaction_threshold_trigger.gd
)
interaction_threshold_trigger.gdA component that tracks how many times an object has been interacted with.
- Use for: "Stop Poking Me" voice lines, breaking walls after N hits, hidden achievements.
- Behavior: Counts signals -> Emits at specific counts.
threshold_reached
一个追踪对象被交互次数的组件。
- 用途:“别再戳我了”语音台词、击打N次后破坏墙壁、隐藏成就。
- 行为:统计信号 -> 在达到特定次数时触发信号。
threshold_reached
3. Secret Persistence (secret_persistence_handler.gd
)
secret_persistence_handler.gd3. Secret Persistence (secret_persistence_handler.gd
)
secret_persistence_handler.gdA standardized way to save/load "Unlocked" states.
- Use for: Ensuring a player doesn't have to re-enter a code every session.
- Behavior: Wraps to save boolean flags to
ConfigFile.user://secrets.cfg
一种标准化的保存/加载“已解锁”状态的方式。
- 用途:确保玩家无需在每次会话中重新输入代码。
- 行为:封装,将布尔标志保存到
ConfigFile。user://secrets.cfg
Usage Example (Cheat Code)
用法示例(作弊码)
gdscript
undefinedgdscript
undefinedIn your Game Manager or Player Controller
在你的游戏管理器或玩家控制器中
@onready var cheat_watcher = $InputSequenceWatcher
func _ready():
# Define UP, UP, DOWN, DOWN...
cheat_watcher.sequence = [
"ui_up", "ui_up", "ui_down", "ui_down"
]
cheat_watcher.sequence_matched.connect(_on_cheat_unlocked)
func _on_cheat_unlocked():
print("God Mode Enabled!")
SecretPersistence.unlock_secret("god_mode")
undefined@onready var cheat_watcher = $InputSequenceWatcher
func _ready():
# 定义上、上、下、下...
cheat_watcher.sequence = [
"ui_up", "ui_up", "ui_down", "ui_down"
]
cheat_watcher.sequence_matched.connect(_on_cheat_unlocked)
func _on_cheat_unlocked():
print("上帝模式已启用!")
SecretPersistence.unlock_secret("god_mode")
undefinedAnti-Patterns
反模式
- NEVER Hardcode Input Checks: NEVER use in
Input.is_action_just_pressedfor sequences. It is frame-dependent and brittle. ALWAYS use an event-based buffer._process - NEVER Pollute PlayerPrefs: NEVER save hidden unlockables in the user's main (resolution, volume). If the user deletes settings to fix a graphic glitch, they shouldn't lose their unlocked cheats. Use
settings.cfg.user://secrets.cfg - NEVER Trust Client Inputs for Competitive Secrets: If your secret grants a competitive advantage (e.g., in multiplayer), NEVER validate it solely on the client.
- 绝对不要硬编码输入检查:绝对不要在中使用
_process来检测序列。这依赖于帧率,且非常脆弱。一定要使用基于事件的缓存方式。Input.is_action_just_pressed - 绝对不要污染PlayerPrefs:绝对不要将隐藏的可解锁内容保存到用户的主(分辨率、音量等)中。如果用户删除设置来修复图形故障,他们不应该丢失已解锁的作弊码。请使用
settings.cfg。user://secrets.cfg - 绝对不要信任客户端输入来处理竞技类秘籍:如果你的秘籍会带来竞技优势(如在多人游戏中),绝对不要仅在客户端验证它。