@where-stars-drift/core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +143 -0
  3. package/dist/src/base/bounded-body.d.ts +8 -0
  4. package/dist/src/base/bounded-body.js +10 -0
  5. package/dist/src/base/celestial-body.d.ts +12 -0
  6. package/dist/src/base/celestial-body.js +11 -0
  7. package/dist/src/base/hoverable.d.ts +10 -0
  8. package/dist/src/base/hoverable.js +4 -0
  9. package/dist/src/base/massive-body.d.ts +8 -0
  10. package/dist/src/base/massive-body.js +10 -0
  11. package/dist/src/config/effects.d.ts +14 -0
  12. package/dist/src/config/effects.js +14 -0
  13. package/dist/src/config/grid.d.ts +10 -0
  14. package/dist/src/config/grid.js +10 -0
  15. package/dist/src/config/panel.d.ts +26 -0
  16. package/dist/src/config/panel.js +26 -0
  17. package/dist/src/config/simulation.d.ts +21 -0
  18. package/dist/src/config/simulation.js +23 -0
  19. package/dist/src/controllers/clan-controller.d.ts +7 -0
  20. package/dist/src/controllers/clan-controller.js +12 -0
  21. package/dist/src/controllers/debug-controller.d.ts +45 -0
  22. package/dist/src/controllers/debug-controller.js +82 -0
  23. package/dist/src/controllers/effects-controller.d.ts +17 -0
  24. package/dist/src/controllers/effects-controller.js +71 -0
  25. package/dist/src/controllers/hover-controller.d.ts +11 -0
  26. package/dist/src/controllers/hover-controller.js +107 -0
  27. package/dist/src/controllers/layer-controller.d.ts +16 -0
  28. package/dist/src/controllers/layer-controller.js +64 -0
  29. package/dist/src/controllers/physics-controller.d.ts +14 -0
  30. package/dist/src/controllers/physics-controller.js +152 -0
  31. package/dist/src/controllers/star-controller.d.ts +12 -0
  32. package/dist/src/controllers/star-controller.js +38 -0
  33. package/dist/src/controllers/starship-controller.d.ts +17 -0
  34. package/dist/src/controllers/starship-controller.js +58 -0
  35. package/dist/src/draw-debug-line.d.ts +9 -0
  36. package/dist/src/draw-debug-line.js +29 -0
  37. package/dist/src/entities/black-hole-factory.d.ts +15 -0
  38. package/dist/src/entities/black-hole-factory.js +23 -0
  39. package/dist/src/entities/black-hole-shapes.d.ts +9 -0
  40. package/dist/src/entities/black-hole-shapes.js +224 -0
  41. package/dist/src/entities/black-hole.d.ts +69 -0
  42. package/dist/src/entities/black-hole.js +210 -0
  43. package/dist/src/entities/clan-manager.d.ts +12 -0
  44. package/dist/src/entities/clan-manager.js +22 -0
  45. package/dist/src/entities/clans.d.ts +15 -0
  46. package/dist/src/entities/clans.js +76 -0
  47. package/dist/src/entities/comet.d.ts +27 -0
  48. package/dist/src/entities/comet.js +81 -0
  49. package/dist/src/entities/docking-point.d.ts +20 -0
  50. package/dist/src/entities/docking-point.js +22 -0
  51. package/dist/src/entities/fleet.d.ts +45 -0
  52. package/dist/src/entities/fleet.js +374 -0
  53. package/dist/src/entities/formations.d.ts +51 -0
  54. package/dist/src/entities/formations.js +340 -0
  55. package/dist/src/entities/meteor.d.ts +26 -0
  56. package/dist/src/entities/meteor.js +48 -0
  57. package/dist/src/entities/nebula.d.ts +18 -0
  58. package/dist/src/entities/nebula.js +43 -0
  59. package/dist/src/entities/orbit.d.ts +23 -0
  60. package/dist/src/entities/orbit.js +43 -0
  61. package/dist/src/entities/pulsar.d.ts +18 -0
  62. package/dist/src/entities/pulsar.js +41 -0
  63. package/dist/src/entities/ring.d.ts +13 -0
  64. package/dist/src/entities/ring.js +26 -0
  65. package/dist/src/entities/ringed-planet.d.ts +21 -0
  66. package/dist/src/entities/ringed-planet.js +68 -0
  67. package/dist/src/entities/sector-grid.d.ts +16 -0
  68. package/dist/src/entities/sector-grid.js +70 -0
  69. package/dist/src/entities/star-factory.d.ts +29 -0
  70. package/dist/src/entities/star-factory.js +47 -0
  71. package/dist/src/entities/star.d.ts +48 -0
  72. package/dist/src/entities/star.js +167 -0
  73. package/dist/src/entities/starship-classes.d.ts +0 -0
  74. package/dist/src/entities/starship-classes.js +2 -0
  75. package/dist/src/entities/starship.d.ts +91 -0
  76. package/dist/src/entities/starship.js +760 -0
  77. package/dist/src/entities/supernova.d.ts +26 -0
  78. package/dist/src/entities/supernova.js +54 -0
  79. package/dist/src/index.d.ts +20 -0
  80. package/dist/src/index.js +19 -0
  81. package/dist/src/lib/energy-stream.d.ts +5 -0
  82. package/dist/src/lib/energy-stream.js +98 -0
  83. package/dist/src/lib/quadtree.d.ts +31 -0
  84. package/dist/src/lib/quadtree.js +124 -0
  85. package/dist/src/lib/simplified-stream.d.ts +6 -0
  86. package/dist/src/lib/simplified-stream.js +19 -0
  87. package/dist/src/types.d.ts +14 -0
  88. package/dist/src/types.js +1 -0
  89. package/dist/src/ui/black-holes-panel.d.ts +2 -0
  90. package/dist/src/ui/black-holes-panel.js +76 -0
  91. package/dist/src/ui/clans-panel.d.ts +2 -0
  92. package/dist/src/ui/clans-panel.js +20 -0
  93. package/dist/src/ui/debug-panel-controller.d.ts +41 -0
  94. package/dist/src/ui/debug-panel-controller.js +285 -0
  95. package/dist/src/ui/fleets-panel.d.ts +2 -0
  96. package/dist/src/ui/fleets-panel.js +127 -0
  97. package/dist/src/ui/formations-panel.d.ts +3 -0
  98. package/dist/src/ui/formations-panel.js +129 -0
  99. package/dist/src/ui/panel-config.d.ts +26 -0
  100. package/dist/src/ui/panel-config.js +26 -0
  101. package/dist/src/ui/ships-panel.d.ts +12 -0
  102. package/dist/src/ui/ships-panel.js +61 -0
  103. package/dist/src/ui/stars-panel.d.ts +2 -0
  104. package/dist/src/ui/stars-panel.js +120 -0
  105. package/dist/src/where-stars-drift.d.ts +71 -0
  106. package/dist/src/where-stars-drift.js +440 -0
  107. package/dist/tsconfig.tsbuildinfo +1 -0
  108. package/package.json +35 -0
  109. package/src/base/bounded-body.ts +14 -0
  110. package/src/base/celestial-body.ts +20 -0
  111. package/src/base/hoverable.ts +11 -0
  112. package/src/base/massive-body.ts +14 -0
  113. package/src/config/effects.ts +15 -0
  114. package/src/config/grid.ts +11 -0
  115. package/src/config/panel.ts +26 -0
  116. package/src/config/simulation.ts +25 -0
  117. package/src/controllers/clan-controller.ts +19 -0
  118. package/src/controllers/debug-controller.ts +112 -0
  119. package/src/controllers/effects-controller.ts +86 -0
  120. package/src/controllers/hover-controller.ts +128 -0
  121. package/src/controllers/layer-controller.ts +78 -0
  122. package/src/controllers/physics-controller.ts +173 -0
  123. package/src/controllers/star-controller.ts +51 -0
  124. package/src/controllers/starship-controller.ts +76 -0
  125. package/src/draw-debug-line.ts +37 -0
  126. package/src/entities/black-hole-factory.ts +28 -0
  127. package/src/entities/black-hole-shapes.ts +276 -0
  128. package/src/entities/black-hole.ts +246 -0
  129. package/src/entities/clan-manager.ts +33 -0
  130. package/src/entities/clans.ts +98 -0
  131. package/src/entities/comet.ts +102 -0
  132. package/src/entities/docking-point.ts +34 -0
  133. package/src/entities/fleet.ts +446 -0
  134. package/src/entities/formations.ts +423 -0
  135. package/src/entities/meteor.ts +59 -0
  136. package/src/entities/nebula.ts +50 -0
  137. package/src/entities/orbit.ts +53 -0
  138. package/src/entities/pulsar.ts +64 -0
  139. package/src/entities/ring.ts +42 -0
  140. package/src/entities/ringed-planet.ts +85 -0
  141. package/src/entities/sector-grid.ts +81 -0
  142. package/src/entities/star-factory.ts +59 -0
  143. package/src/entities/star.ts +222 -0
  144. package/src/entities/starship-classes.ts +1 -0
  145. package/src/entities/starship.ts +906 -0
  146. package/src/entities/supernova.ts +75 -0
  147. package/src/index.ts +24 -0
  148. package/src/lib/energy-stream.ts +127 -0
  149. package/src/lib/quadtree.ts +159 -0
  150. package/src/lib/simplified-stream.ts +28 -0
  151. package/src/types.ts +16 -0
  152. package/src/ui/black-holes-panel.ts +91 -0
  153. package/src/ui/clans-panel.ts +27 -0
  154. package/src/ui/debug-panel-controller.ts +339 -0
  155. package/src/ui/fleets-panel.ts +153 -0
  156. package/src/ui/formations-panel.ts +155 -0
  157. package/src/ui/panel-config.ts +26 -0
  158. package/src/ui/ships-panel.ts +85 -0
  159. package/src/ui/stars-panel.ts +146 -0
  160. package/src/where-stars-drift.ts +542 -0
@@ -0,0 +1,61 @@
1
+ import { PANEL_CONFIG } from './panel-config';
2
+ export function drawStarshipCatalog(ctx, startY, shipCatalog) {
3
+ let currentY = startY + PANEL_CONFIG.PADDING;
4
+ Object.keys(shipCatalog).forEach(groupName => {
5
+ // Draw Main Group Header (Military / Non-Military)
6
+ ctx.font = PANEL_CONFIG.GROUP_FONT;
7
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
8
+ ctx.textAlign = 'left';
9
+ ctx.textBaseline = 'top';
10
+ ctx.fillText(groupName, PANEL_CONFIG.X + PANEL_CONFIG.PADDING, currentY);
11
+ currentY += PANEL_CONFIG.GROUP_HEADER_HEIGHT;
12
+ const categories = shipCatalog[groupName];
13
+ Object.keys(categories).forEach(categoryName => {
14
+ // Draw Category Header (Capital, Cruiser, etc.)
15
+ ctx.font = PANEL_CONFIG.ROW_FONT;
16
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
17
+ ctx.fillText(categoryName, PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 10, currentY);
18
+ currentY += PANEL_CONFIG.ROW_HEIGHT * 0.8;
19
+ const shipClasses = categories[categoryName];
20
+ shipClasses.forEach(shipClassEntry => {
21
+ // Draw ship class name once
22
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
23
+ ctx.font = PANEL_CONFIG.ROW_FONT;
24
+ ctx.fillText(shipClassEntry.template.name, PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 20, currentY);
25
+ currentY += PANEL_CONFIG.ROW_HEIGHT;
26
+ // Loop through variants and draw them vertically
27
+ shipClassEntry.variants.forEach((variant, index) => {
28
+ const rowHeight = 40;
29
+ const vizX = PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 40;
30
+ const vizY = currentY + rowHeight / 2;
31
+ ctx.save();
32
+ ctx.translate(vizX, vizY);
33
+ ctx.rotate(-Math.PI / 2); // Point ships to the right
34
+ ctx.beginPath();
35
+ variant(ctx, shipClassEntry.template.radius * PANEL_CONFIG.SHIP_RENDER_SCALE);
36
+ ctx.fillStyle = shipClassEntry.template.color;
37
+ ctx.strokeStyle = '#fff';
38
+ ctx.lineWidth = 0.5;
39
+ ctx.fill();
40
+ ctx.stroke();
41
+ ctx.restore();
42
+ // Draw details on the right
43
+ const detailsX = vizX + 40;
44
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
45
+ ctx.font = '11px "Roboto Mono", monospace';
46
+ ctx.textAlign = 'left';
47
+ ctx.textBaseline = 'top';
48
+ ctx.fillText(`Variant ${index + 1}`, detailsX, currentY + 5);
49
+ ctx.font = '10px "Roboto Mono", monospace';
50
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
51
+ ctx.fillText(`Radius: ${shipClassEntry.template.radius.toFixed(1)}px`, detailsX, currentY + 20);
52
+ ctx.fillText(`Color: ${shipClassEntry.template.color}`, detailsX + 90, currentY + 20);
53
+ currentY += rowHeight;
54
+ });
55
+ currentY += 10; // Extra padding after variants for a class
56
+ });
57
+ });
58
+ currentY += PANEL_CONFIG.ROW_HEIGHT / 2; // Extra space between main groups
59
+ });
60
+ return currentY - startY;
61
+ }
@@ -0,0 +1,2 @@
1
+ import { Star } from '../entities/star';
2
+ export declare function drawStarCatalog(ctx: CanvasRenderingContext2D, startY: number, catalogStars: Star[], pulseTime: number): number;
@@ -0,0 +1,120 @@
1
+ import { Star } from '../entities/star';
2
+ import { Pulsar } from '../entities/pulsar';
3
+ import { RingedPlanet } from '../entities/ringed-planet';
4
+ import { PANEL_CONFIG } from './panel-config';
5
+ function drawStarParameters(ctx, star, x, y) {
6
+ ctx.font = '10px "Roboto Mono", monospace';
7
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
8
+ ctx.textAlign = 'left';
9
+ ctx.textBaseline = 'top';
10
+ let currentY = y;
11
+ const lineHeight = 12;
12
+ const params = [
13
+ { label: 'Radius', value: star.baseRadius.toFixed(2) },
14
+ { label: 'Mass', value: star.mass.toFixed(2) },
15
+ { label: 'Color', value: star.color },
16
+ { label: 'Aura', value: star.hasAura.toString() },
17
+ ];
18
+ if (star instanceof Pulsar) {
19
+ params.push({ label: 'Blink Speed', value: star.pulsationSpeed.toFixed(2) });
20
+ }
21
+ if (star instanceof RingedPlanet) {
22
+ params.push({ label: 'Rings', value: star.rings.length.toString() });
23
+ }
24
+ params.forEach(param => {
25
+ ctx.fillText(`${param.label}:`, x, currentY);
26
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
27
+ ctx.fillText(param.value, x + 70, currentY);
28
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
29
+ currentY += lineHeight;
30
+ });
31
+ }
32
+ export function drawStarCatalog(ctx, startY, catalogStars, pulseTime) {
33
+ let currentY = startY + PANEL_CONFIG.PADDING;
34
+ const starTypes = [
35
+ { name: 'Standard Star', ctor: Star },
36
+ { name: 'Pulsar', ctor: Pulsar },
37
+ { name: 'Ringed Planet', ctor: RingedPlanet },
38
+ ];
39
+ starTypes.forEach(typeInfo => {
40
+ ctx.font = PANEL_CONFIG.GROUP_FONT;
41
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
42
+ ctx.textAlign = 'left';
43
+ ctx.textBaseline = 'top';
44
+ ctx.fillText(typeInfo.name, PANEL_CONFIG.X + PANEL_CONFIG.PADDING, currentY);
45
+ currentY += PANEL_CONFIG.GROUP_HEADER_HEIGHT;
46
+ const variations = catalogStars.filter(star => {
47
+ if (typeInfo.ctor === Star) {
48
+ return star.constructor === Star;
49
+ }
50
+ return star instanceof typeInfo.ctor;
51
+ });
52
+ if (variations.length === 0) {
53
+ ctx.font = '10px "Roboto Mono", monospace';
54
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
55
+ ctx.fillText('No variations available for this type.', PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 10, currentY);
56
+ currentY += 20;
57
+ return;
58
+ }
59
+ variations.forEach((sampleStar) => {
60
+ const rowY = currentY + 30;
61
+ const xPos = PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 20;
62
+ // Draw star visualization
63
+ ctx.save();
64
+ ctx.translate(xPos, rowY);
65
+ if (sampleStar instanceof Pulsar) {
66
+ // Update animation without moving the star by passing 0 for width/height
67
+ sampleStar.update(ctx, 0, 0, { dx: 0, dy: 0 }, false, false, pulseTime);
68
+ sampleStar.draw(ctx, pulseTime);
69
+ }
70
+ else {
71
+ const originalAura = sampleStar.hasAura;
72
+ sampleStar.hasAura = false; // Disable aura for performance in catalog
73
+ sampleStar.draw(ctx, 0); // Draw star statically
74
+ sampleStar.hasAura = originalAura; // Restore it for parameter display
75
+ }
76
+ ctx.restore();
77
+ // Draw star parameters
78
+ drawStarParameters(ctx, sampleStar, xPos + 40, rowY - 20);
79
+ // If it's a ringed planet, draw ring details
80
+ if (sampleStar instanceof RingedPlanet) {
81
+ const planet = sampleStar;
82
+ let ringListY = currentY + 80;
83
+ ctx.font = '10px "Roboto Mono", monospace';
84
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
85
+ ctx.fillText("Ring Composition:", xPos + 40, ringListY);
86
+ ringListY += 20;
87
+ planet.rings.forEach((ring, index) => {
88
+ const ringDisplayRadius = ring.radius * 0.5; // Scale down for display
89
+ const ringCenterY = ringListY + ringDisplayRadius + 5;
90
+ // Draw the ring visualization
91
+ ctx.save();
92
+ ctx.translate(xPos + 10, ringCenterY);
93
+ ring.draw(ctx);
94
+ ctx.restore();
95
+ // Draw ring parameters
96
+ const paramX = xPos + 40;
97
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
98
+ ctx.fillText(`Ring ${index + 1}: r=${ring.radius.toFixed(1)}, th=${ring.thickness.toFixed(1)}, dotted=${ring.isDotted}`, paramX, ringCenterY - 5);
99
+ ringListY += (ringDisplayRadius * 2) + 15;
100
+ // Draw separator line
101
+ if (index < planet.rings.length - 1) {
102
+ ctx.beginPath();
103
+ ctx.moveTo(paramX - 5, ringListY);
104
+ ctx.lineTo(PANEL_CONFIG.X + PANEL_CONFIG.WIDTH - PANEL_CONFIG.PADDING, ringListY);
105
+ ctx.strokeStyle = PANEL_CONFIG.BORDER_COLOR;
106
+ ctx.lineWidth = 0.5;
107
+ ctx.stroke();
108
+ ringListY += 10;
109
+ }
110
+ });
111
+ currentY = ringListY;
112
+ }
113
+ else {
114
+ currentY += 80;
115
+ }
116
+ });
117
+ currentY += 20; // Space between categories
118
+ });
119
+ return currentY - startY;
120
+ }
@@ -0,0 +1,71 @@
1
+ export interface SimulationConfig {
2
+ starsCount?: number;
3
+ interactive?: boolean;
4
+ debug?: boolean;
5
+ showCatalog?: boolean;
6
+ showGrid?: boolean;
7
+ showGithubLink?: boolean;
8
+ }
9
+ export interface SimulationStats {
10
+ fps: number;
11
+ avgFps: number;
12
+ starCount: number;
13
+ starshipCount: number;
14
+ frameCount: number;
15
+ }
16
+ export declare class WhereStarsDrift {
17
+ private canvas;
18
+ private ctx;
19
+ private config;
20
+ private width;
21
+ private height;
22
+ private layerController;
23
+ private starController;
24
+ private starshipController;
25
+ private physicsController;
26
+ private effectsController;
27
+ private debugController;
28
+ private debugPanelController;
29
+ private hoverController;
30
+ private allLayers;
31
+ private allBodies;
32
+ private quadtree;
33
+ private mouse;
34
+ private isMouseInside;
35
+ private animationFrameId;
36
+ private lastTime;
37
+ private pulseTime;
38
+ private githubLinkBounds;
39
+ private isMouseOverGithubLink;
40
+ private frameCount;
41
+ private fps;
42
+ private fpsFrameCount;
43
+ private lastFpsUpdateTime;
44
+ private fpsHistory;
45
+ private avgFps;
46
+ private readonly avgFpsWindow;
47
+ constructor(canvas: HTMLCanvasElement, config?: SimulationConfig);
48
+ private _initializeControllers;
49
+ start(): void;
50
+ stop(): void;
51
+ destroy(): void;
52
+ getStats(): SimulationStats;
53
+ setInteractive(enabled: boolean): void;
54
+ setDebug(enabled: boolean): void;
55
+ setShowCatalog(visible: boolean): void;
56
+ setShowGrid(visible: boolean): void;
57
+ setShowGithubLink(visible: boolean): void;
58
+ private _setupEventListeners;
59
+ private _removeEventListeners;
60
+ private _handleMouseMove;
61
+ private _handleMouseEnter;
62
+ private _handleMouseLeave;
63
+ private _handleMouseDown;
64
+ private _handleMouseUp;
65
+ private _handleWheel;
66
+ private _handleResize;
67
+ private _drawGithubIcon;
68
+ private _drawGithubLink;
69
+ private _checkMouseInteraction;
70
+ private animate;
71
+ }