// To see what the result of parsing this file looks like, copy the code and
// paste it into the editor at https://flecs.dev/explorer
//
// To load this file yourself, call ecs_plecs_from_file("reflection.flecs");

// It is possible to set component values in a plecs file as long as the 
// component is described with reflection data. Since we don't have a component
// yet, we'll first have to create one.

// Plecs does not have dedicated syntax for describing types, but since the
// reflection addon (flecs.meta) uses regular entities and components to store
// reflection data, we can use existing plecs syntax to create a type.

// First we'll add flecs.meta to the list of namespaces to search. This is not
// strictly necessary, but lets us write Struct instead of flecs.meta.Struct
using flecs.meta

// We can now create a struct like this. "Struct Position" is the shorthand
// declaration syntax for "Position :- Struct", and has as benefit that we can
// open a scope after the statement
Struct Position {
  // Add two child entities with the Member component
  x :- Member{type: f32}
  y :- Member{type: f32}
}

// Plecs has a feature which makes it possible to specify a default type for a
// scope. The Struct component has Member as default type. This means we can
// also create a type like this, which is a bit shorter:
Struct Mass {
  value :- {f32} // 'type' can be ommitted since it's the first member
}

// Similarly we can also define an enumeration type. The default scope type for
// Enum is Constant, which ensures amongst others that the child entities will
// be assigned with an incremenenting constant value automatically.
Enum Color {
  Red
  Green
  Blue
}

// We can now create an entity that uses the types
my_entity {
  - Position {x: 10, y: 20}
  - Mass {100} // Member names are optional
  - Color {Green} // Green will be automatically looked up in the Color scope
}
