AuroraCanvasEndpoint.vala 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Astralis;
  2. using Invercargill;
  3. using Invercargill.DataStructures;
  4. using Inversion;
  5. using Spry;
  6. /**
  7. * AuroraCanvasEndpoint - Returns just the aurora waves for HTMX polling
  8. *
  9. * This endpoint is polled every 5 seconds by the demo page.
  10. * It evolves the aurora state and returns fresh wave HTML.
  11. */
  12. public class AuroraCanvasEndpoint : Component {
  13. private AuroraState aurora_state = inject<AuroraState>();
  14. private ComponentFactory factory = inject<ComponentFactory>();
  15. public override string markup { get {
  16. return """
  17. <spry-outlet sid="waves"/>
  18. """;
  19. }}
  20. public override async void prepare() throws Error {
  21. // Create wave components
  22. var waves = new Series<Renderable>();
  23. foreach (var wave in aurora_state.get_waves()) {
  24. var component = factory.create<AuroraWaveComponent>();
  25. component.y_offset = wave.y_offset;
  26. component.amplitude = wave.amplitude;
  27. component.frequency = wave.frequency;
  28. component.color1 = wave.color1;
  29. component.color2 = wave.color2;
  30. component.opacity = wave.opacity;
  31. component.animation_delay = wave.animation_delay;
  32. waves.add(component);
  33. }
  34. set_outlet_children("waves", waves);
  35. }
  36. public async override void handle_action(string action) throws Error {
  37. if (action == "Poll") {
  38. // Evolve the aurora naturally when polled
  39. aurora_state.evolve();
  40. // prepare() will be called automatically to render the waves
  41. }
  42. }
  43. }