Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
1.7 kB · 54 lines
MDX
at develop
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455---title: ECS Components---
import { ECSComponentDocs } from "./ECSComponentDocs";
# ECS Components
ECS Components are the building blocks of entities. They define the datastructures can be assigned to entities to make them more than just an ID.
## Defining Components
Components are defined using Zod schemas, with a `z.object` at the root.
Components should contain as many properties for that component that areexclusive to that component. Properties should be defined with a type and eitherinclude a default value or be listed as optional. This helps with type safetyand auto-complete.
If a property might be useful to have on many kinds of entities, it should besplit out into its own component. Good judgement should be applied here. Itmakes sense to have a separate `heat` component so engine entities, reactorentities, and phaser entities can all use the single component. However, usingthat same `heat` component for a star might not make as much sense, since welikely won't simulate variations in star heat.
Here's an example of the identity component, which includes two properties.Notice the JSDoc comments which can be useful for knowing more context about theproperty. For example, a comment can be added explaining the temperature scaleused for heat.
```ts// /server/src/components/identity.tsimport {z} from "zod";
export const identity = z.object({ static id = "identity" as const;
/** * The name of the entity. */ name: z.string().default("Entity"),
/** * Should only be used for information provided by the Flight Director */ description: z.string().optional()}).default({})```
## Component Properties
<ECSComponentDocs />