Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag interfaces #7

Closed
wants to merge 2 commits into from
Closed

Flag interfaces #7

wants to merge 2 commits into from

Conversation

hautajoki
Copy link
Collaborator

this pr adds support for flag interfaces not associated with any component data.

`// A component that stores data
interface Position {
    x: number;
    y: number;
}

// A flag (contains no data)
interface Alive extends Flag {}

const ball = spawn();

// Components with data must be assigned using set()
set<Position>(ball, { x: 10, y: 20 });

// @ts-expect-error: Cannot use add() with components that contain data
add<Position>(ball);

// @ts-expect-error: Cannot use set() with flag components
set<Alive>(ball, true);

// Tag components can only be added or removed
add<Alive>(ball);

// Flags can also be used  with spawn/insert functions
const cube = spawn<[Alive]>()

const torus = spawn()
insert<[Position, Alive]>([{ x: 10, y: 20 }])

@hautajoki hautajoki requested a review from Ukendio November 1, 2024 11:26
@Ukendio
Copy link
Collaborator

Ukendio commented Nov 1, 2024

I dont like that it is called a Flag and not a Tag. It doesnt really represent the same things. You can use Tags as flags for certain things, but can also be representative of symbolic state.

@@ -462,7 +489,7 @@ export function parent(entity: Entity): Entity | undefined {
* @returns The pair ID.
* @metadata macro
*/
export function pair<P>(object: Entity, predicate?: ComponentKey<P>): Pair<P, unknown> {
export function pair<P>(object: Entity, predicate?: ComponentKey<P>): Pair<OmitFlag<P>, unknown> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw thiis but the first element is the predicate not the object.

Copy link
Collaborator Author

@hautajoki hautajoki Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The predicate here is a flamework generated key. pair<SomeComponent>(object)

@@ -3,8 +3,12 @@ import * as ecs from "@rbxts/jecs";

import { createSignal, type Signal } from "./signal";

export interface Wildcard {}
export interface ChildOf {}
export interface Flag {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the name of this interface and every subsequent dependents on this interface to use "Tag"

Copy link
Collaborator Author

@hautajoki hautajoki Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag is already used for Entity<.undefined>. Should I just get rid of that then?

Copy link
Collaborator

@Ukendio Ukendio Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just get rid of that then?

Yeah, that sounds reasonable.

@hautajoki hautajoki closed this Nov 4, 2024
@hautajoki hautajoki deleted the tag-support branch November 4, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants