Skip to content
godot-coding-standards logo

Godot 4.x 核心架构原则

godot-coding-standards

Godot 4.x 核心架构原则。当设计、审查 Godot 组件和系统时使用。关注:组件模式、信号通信、Resource设计、系统架构。触发词:godot, 组件, 信号, 架构, 设计。

SKILL.md

Full skill instructions

Godot 4.x 核心架构原则

为 Godot 4.x 项目设计的核心原则,确保代码的通用性、模块化、可复用性、简洁性。

核心设计原则

1. 通用性优先

  • 使用 @export 暴露可配置参数,避免硬编码
  • 组件应该能在不同场景中复用,不依赖特定父节点
  • 通过配置而非代码修改来调整行为

2. 模块化设计

  • 单一职责:每个组件只做一件事(Health、Movement、Attack)
  • 组件化思维:用小组件组合出复杂行为,避免巨型类
  • 信号松耦合:通过信号通信,避免直接调用和硬依赖

3. 可复用性

  • Resource 类:用于存储配置数据(Damage、SkillData)
  • 清晰接口:公共方法定义清晰,private方法用 _ 前缀
  • 独立性:组件可以独立测试和使用

4. 简洁实用

  • 注重实用性,避免过度设计
  • 不为未来需求预先设计
  • 代码自解释,复杂逻辑才加注释

组件模式示例

基础组件模板

extends Node
class_name Health

## 可复用的生命值组件
## 通过信号通知状态变化,不依赖特定父节点

signal health_changed(current: float, maximum: float)
signal died()

@export var max_health: float = 100.0

var health: float = max_health:
    set(val):
        health = clamp(val, 0, max_health)
        health_changed.emit(health, max_health)
        if health <= 0:
            died.emit()

func take_damage(amount: float) -> void:
    health -= amount

func heal(amount: float) -> void:
    health += amount

Resource 数据类

extends Resource
class_name Damage

## 伤害数据配置类
## 可在编辑器中创建 .tres 资源文件

@export var base_damage: float = 10.0
@export var damage_type: String = "physical"
@export_group("Effects")
@export var knockback_force: float = 0.0
@export var stun_duration: float = 0.0

架构检查要点

  • 通用性:是否使用 @export 配置化?能否跨场景复用?
  • 模块化:是否单一职责?是否用信号解耦?
  • 可复用性:是否有清晰接口?Resource 类是否正确使用?
  • 简洁性:是否避免过度设计?代码是否自解释?

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View