Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

bevy-mechanic-secrets

БесплатноБез исполняемых скриптовНе проверен

Bevy ECS skill for secrets and discovery flags. Keywords: Bevy, secrets, discovery, flags, ECS.

thedivergentaiот thedivergentai★ 1 019 звёзд на GitHub

Об этом скилле

Bevy secrets mechanic

When to use

Load this when the player uncovers optional flags that must persist.

ECS shape

  • Components: a secret id and a found-set resource you define.
  • Resources: run-wide tables live in a resource (bevy-data-resources), not an autoload.
  • Systems: mutate those components on Update or the fixed timestep. Use .chain() when damage must land before death.
  • Messages: one-shot facts (hit, pickup, quest advance) go through bevy-events-messaging. This file does not add a new event type name.

Coming from Godot

Godot idea Bevy idiom
Secret id A component on the world object.
Found set A resource of ids.
Persist Hand the set to bevy-save-load.

Scope

Secret ids, a discovered set, look-at checks, and timed input sequences are components and resources you own. Persistence of that set belongs on bevy-save-load.

Examples

[dependencies]
bevy = "0.20"
serde = { version = "1", features = ["derive"] }

Discovering a secret inserts its id once. A later system can hand Discovered to the save skill.

use serde::{Deserialize, Serialize};
use std::collections::HashSet;

#[derive(Component)]
struct Secret {
    id: u32,
    radius: f32,
}

#[derive(Component)]
struct Seeker;

#[derive(Resource, Default, Serialize, Deserialize)]
struct Discovered {
    ids: HashSet<u32>,
}

fn discover(
    seekers: Query<&Transform, With<Seeker>>,
    secrets: Query<(&Transform, &Secret)>,
    mut found: ResMut<Discovered>,
) {
    for seeker in &seekers {
        for (tf, secret) in &secrets {
            if seeker.translation.distance(tf.translation) <= secret.radius {
                found.ids.insert(secret.id);
            }
        }
    }
}

fn look_at_secret(
    seekers: Query<&Transform, With<Seeker>>,
    secrets: Query<(&Transform, &Secret)>,
    mut found: ResMut<Discovered>,
) {
    for seeker in &seekers {
        let forward = seeker.forward().as_vec3();
        for (tf, secret) in &secrets {
            let to = tf.translation - seeker.translation;
            let dist = to.length();
            if dist < 0.001 || dist > 6.0 {
                continue;
            }
            if (to / dist).dot(forward) > 0.98 {
                found.ids.insert(secret.id);
            }
        }
    }
}

A sequence matcher keeps a rolling window. The classic up-up-down-down-left-right-left-right pattern unlocks when the tail matches before the window expires.

#[derive(Resource)]
struct SequenceSecret {
    pattern: Vec<KeyCode>,
    heard: Vec<KeyCode>,
    time_left: f32,
    window: f32,
    unlocked: bool,
}

impl Default for SequenceSecret {
    fn default() -> Self {
        Self {
            pattern: vec![
                KeyCode::ArrowUp,
                KeyCode::ArrowUp,
                KeyCode::ArrowDown,
                KeyCode::ArrowDown,
                KeyCode::ArrowLeft,
                KeyCode::ArrowRight,
                KeyCode::ArrowLeft,
                KeyCode::ArrowRight,
            ],
            heard: Vec::new(),
            time_left: 0.0,
            window: 2.5,
            unlocked: false,
        }
    }
}

#[derive(Resource, Default)]
struct Discovered {
    ids: std::collections::HashSet<u32>,
}

fn match_sequence(time: Res<Time>, keys: Res<ButtonInput<KeyCode>>, mut seq: ResMut<SequenceSecret>) {
    if seq.unlocked {
        return;
    }
    let dt = time.delta_secs();
    seq.time_left = (seq.time_left - dt).max(0.0);
    if seq.time_left == 0.0 {
        seq.heard.clear();
    }
    let watched = [
        KeyCode::ArrowUp,
        KeyCode::ArrowDown,
        KeyCode::ArrowLeft,
        KeyCode::ArrowRight,
    ];
    for key in watched {
        if keys.just_pressed(key) {
            seq.heard.push(key);
            seq.time_left = seq.window;
        }
    }
    if seq.heard.len() > seq.pattern.len() {
        let extra = seq.heard.len() - seq.pattern.len();
        seq.heard.drain(0..extra);
    }
    if seq.heard == seq.pattern {
        seq.unlocked = true;
        seq.heard.clear();
    }
}

#[derive(Resource)]
struct ProgressUnlock {
    cleared: u32,
    total: u32,
    unlocked: bool,
}

fn unlock_by_progress(mut progress: ResMut<ProgressUnlock>, mut found: ResMut<Discovered>) {
    if progress.unlocked || progress.total == 0 {
        return;
    }
    if progress.cleared * 100 / progress.total >= 80 {
        progress.unlocked = true;
        found.ids.insert(9001);
    }
}

pub struct SecretsPlugin;

impl Plugin for SecretsPlugin {
    fn build(&self, app: &mut App) {
        app.init_resource::<Discovered>()
            .init_resource::<SequenceSecret>()
            .insert_resource(ProgressUnlock {
                cleared: 0,
                total: 10,
                unlocked: false,
            })
            .add_systems(Update, (match_sequence, unlock_by_progress));
    }
}

Expert Knowledge Delta

Target: Bevy 0.20+.

Core ECS types:

Полный SKILL.md на GitHub

Установить bevy-mechanic-secrets в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/ecs-ownership.md

FAQ

Что делает скилл bevy-mechanic-secrets?

Bevy ECS skill for secrets and discovery flags. Keywords: Bevy, secrets, discovery, flags, ECS.

Как установить скилл bevy-mechanic-secrets?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл bevy-mechanic-secrets запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить bevy-mechanic-secrets с