lifetime property

Definition of LifetimeComponent, saved as LifetimeComponent; a new one lasts 3 seconds.

Implementation

static ComponentDefinition<LifetimeComponent> get lifetime =>
    ComponentDefinition<LifetimeComponent>(
      type: 'LifetimeComponent',
      hints: const ComponentHints(
        name: 'Lifetime',
        group: 'Gameplay',
        description: 'Destroys the entity after a delay.',
        icon: Icons.timer,
        accentColor: Color(0xFF66BB6A),
        fields: {
          'initialLifetime': FieldHint(
            label: 'Duration (s)',
            scrub: ScrubHint(step: 0.1, fractionDigits: 2),
          ),
        },
      ),
      create: () => LifetimeComponent(3.0),
      fields: [
        _d(
          'initialLifetime',
          (c) => (c as LifetimeComponent).initialLifetime,
          (c, v) {
            (c as LifetimeComponent)
              ..initialLifetime = v
              ..timeRemaining = v;
          },
          min: 0,
        ),
      ],
    );