У меня проблема с машинописью.
В настоящее время я работаю над небольшим игровым движком, который использует модель сущность-компонент-система. Я хочу «сериализовать» типы интерфейса в массив классов (типы каждого свойства интерфейса), чтобы информировать систему о необходимых компонентах.
Что я хочу достичь в идеале:
export interface IMovable {
position: CompPosition;
velocity: CompVelocity;
}
export class MoveSystem extends System<IMovable> {
// This array should have type, to ensure all components classes from IMovable are listed.
protected requiredComponents = [ CompPosition, CompVelocity ];
/// ...
}
Что я хочу сделать по крайней мере:
export interface IMovable {
position: CompPosition;
velocity: CompVelocity;
}
export class MoveSystem extends System<IMovable> {
/* The properties of requiredComponents have the same name as in interface, but their types are
different - in interface, the type requires instances (which I want to keep this way in the
interface), but requiredComponents should contain classes. */
protected requiredComponents = {
position: CompPosition,
velocity: CompVelocity
};
/// ...
}
Спасибо за каждое предложение.