@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,85 @@
1
+
2
+ import type { ShipClass } from '../entities/starship';
3
+ import { PANEL_CONFIG } from './panel-config';
4
+
5
+ export type ShipCatalogEntry = {
6
+ template: Omit<ShipClass, 'shape' | 'accentColor'> & { shapeKey: string };
7
+ variants: ((ctx: CanvasRenderingContext2D, r: number) => void)[];
8
+ }
9
+
10
+ export type ShipCatalog = {
11
+ 'Military': Record<string, ShipCatalogEntry[]>;
12
+ 'Non-Military': Record<string, ShipCatalogEntry[]>;
13
+ }
14
+
15
+ export function drawStarshipCatalog(ctx: CanvasRenderingContext2D, startY: number, shipCatalog: ShipCatalog): number {
16
+ let currentY = startY + PANEL_CONFIG.PADDING;
17
+
18
+ (Object.keys(shipCatalog) as Array<keyof ShipCatalog>).forEach(groupName => {
19
+ // Draw Main Group Header (Military / Non-Military)
20
+ ctx.font = PANEL_CONFIG.GROUP_FONT;
21
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
22
+ ctx.textAlign = 'left';
23
+ ctx.textBaseline = 'top';
24
+ ctx.fillText(groupName, PANEL_CONFIG.X + PANEL_CONFIG.PADDING, currentY);
25
+ currentY += PANEL_CONFIG.GROUP_HEADER_HEIGHT;
26
+
27
+ const categories = shipCatalog[groupName];
28
+ Object.keys(categories).forEach(categoryName => {
29
+ // Draw Category Header (Capital, Cruiser, etc.)
30
+ ctx.font = PANEL_CONFIG.ROW_FONT;
31
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
32
+ ctx.fillText(categoryName, PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 10, currentY);
33
+ currentY += PANEL_CONFIG.ROW_HEIGHT * 0.8;
34
+
35
+ const shipClasses = categories[categoryName];
36
+ shipClasses.forEach(shipClassEntry => {
37
+ // Draw ship class name once
38
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
39
+ ctx.font = PANEL_CONFIG.ROW_FONT;
40
+ ctx.fillText(shipClassEntry.template.name, PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 20, currentY);
41
+ currentY += PANEL_CONFIG.ROW_HEIGHT;
42
+
43
+ // Loop through variants and draw them vertically
44
+ shipClassEntry.variants.forEach((variant, index) => {
45
+ const rowHeight = 40;
46
+ const vizX = PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 40;
47
+ const vizY = currentY + rowHeight / 2;
48
+
49
+ ctx.save();
50
+ ctx.translate(vizX, vizY);
51
+ ctx.rotate(-Math.PI / 2); // Point ships to the right
52
+
53
+ ctx.beginPath();
54
+ variant(ctx, shipClassEntry.template.radius * PANEL_CONFIG.SHIP_RENDER_SCALE);
55
+ ctx.fillStyle = shipClassEntry.template.color;
56
+ ctx.strokeStyle = '#fff';
57
+ ctx.lineWidth = 0.5;
58
+ ctx.fill();
59
+ ctx.stroke();
60
+ ctx.restore();
61
+
62
+ // Draw details on the right
63
+ const detailsX = vizX + 40;
64
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
65
+ ctx.font = '11px "Roboto Mono", monospace';
66
+ ctx.textAlign = 'left';
67
+ ctx.textBaseline = 'top';
68
+
69
+ ctx.fillText(`Variant ${index + 1}`, detailsX, currentY + 5);
70
+
71
+ ctx.font = '10px "Roboto Mono", monospace';
72
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
73
+ ctx.fillText(`Radius: ${shipClassEntry.template.radius.toFixed(1)}px`, detailsX, currentY + 20);
74
+ ctx.fillText(`Color: ${shipClassEntry.template.color}`, detailsX + 90, currentY + 20);
75
+
76
+ currentY += rowHeight;
77
+ });
78
+ currentY += 10; // Extra padding after variants for a class
79
+ });
80
+ });
81
+ currentY += PANEL_CONFIG.ROW_HEIGHT / 2; // Extra space between main groups
82
+ });
83
+
84
+ return currentY - startY;
85
+ }
@@ -0,0 +1,146 @@
1
+
2
+ import { Star } from '../entities/star';
3
+ import { Pulsar } from '../entities/pulsar';
4
+ import { RingedPlanet } from '../entities/ringed-planet';
5
+ import { PANEL_CONFIG } from './panel-config';
6
+
7
+ function drawStarParameters(ctx: CanvasRenderingContext2D, star: Star, x: number, y: number) {
8
+ ctx.font = '10px "Roboto Mono", monospace';
9
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
10
+ ctx.textAlign = 'left';
11
+ ctx.textBaseline = 'top';
12
+
13
+ let currentY = y;
14
+ const lineHeight = 12;
15
+
16
+ const params: { label: string; value: string }[] = [
17
+ { label: 'Radius', value: star.baseRadius.toFixed(2) },
18
+ { label: 'Mass', value: star.mass.toFixed(2) },
19
+ { label: 'Color', value: star.color },
20
+ { label: 'Aura', value: star.hasAura.toString() },
21
+ ];
22
+
23
+ if (star instanceof Pulsar) {
24
+ params.push({ label: 'Blink Speed', value: star.pulsationSpeed.toFixed(2) });
25
+ }
26
+ if (star instanceof RingedPlanet) {
27
+ params.push({ label: 'Rings', value: star.rings.length.toString() });
28
+ }
29
+
30
+ params.forEach(param => {
31
+ ctx.fillText(`${param.label}:`, x, currentY);
32
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
33
+ ctx.fillText(param.value, x + 70, currentY);
34
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
35
+ currentY += lineHeight;
36
+ });
37
+ }
38
+
39
+ export function drawStarCatalog(ctx: CanvasRenderingContext2D, startY: number, catalogStars: Star[], pulseTime: number): number {
40
+ let currentY = startY + PANEL_CONFIG.PADDING;
41
+
42
+ const starTypes = [
43
+ { name: 'Standard Star', ctor: Star },
44
+ { name: 'Pulsar', ctor: Pulsar },
45
+ { name: 'Ringed Planet', ctor: RingedPlanet },
46
+ ];
47
+
48
+ starTypes.forEach(typeInfo => {
49
+ ctx.font = PANEL_CONFIG.GROUP_FONT;
50
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
51
+ ctx.textAlign = 'left';
52
+ ctx.textBaseline = 'top';
53
+ ctx.fillText(typeInfo.name, PANEL_CONFIG.X + PANEL_CONFIG.PADDING, currentY);
54
+ currentY += PANEL_CONFIG.GROUP_HEADER_HEIGHT;
55
+
56
+ const variations = catalogStars.filter(star => {
57
+ if (typeInfo.ctor === Star) {
58
+ return star.constructor === Star;
59
+ }
60
+ return star instanceof typeInfo.ctor;
61
+ });
62
+
63
+ if (variations.length === 0) {
64
+ ctx.font = '10px "Roboto Mono", monospace';
65
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
66
+ ctx.fillText('No variations available for this type.', PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 10, currentY);
67
+ currentY += 20;
68
+ return;
69
+ }
70
+
71
+ variations.forEach((sampleStar) => {
72
+ const rowY = currentY + 30;
73
+ const xPos = PANEL_CONFIG.X + PANEL_CONFIG.PADDING + 20;
74
+
75
+ // Draw star visualization
76
+ ctx.save();
77
+ ctx.translate(xPos, rowY);
78
+
79
+ if (sampleStar instanceof Pulsar) {
80
+ // Update animation without moving the star by passing 0 for width/height
81
+ sampleStar.update(ctx, 0, 0, { dx: 0, dy: 0 }, false, false, pulseTime);
82
+ sampleStar.draw(ctx, pulseTime);
83
+ } else {
84
+ const originalAura = sampleStar.hasAura;
85
+ sampleStar.hasAura = false; // Disable aura for performance in catalog
86
+ sampleStar.draw(ctx, 0); // Draw star statically
87
+ sampleStar.hasAura = originalAura; // Restore it for parameter display
88
+ }
89
+
90
+ ctx.restore();
91
+
92
+ // Draw star parameters
93
+ drawStarParameters(ctx, sampleStar, xPos + 40, rowY - 20);
94
+
95
+ // If it's a ringed planet, draw ring details
96
+ if (sampleStar instanceof RingedPlanet) {
97
+ const planet = sampleStar;
98
+ let ringListY = currentY + 80;
99
+ ctx.font = '10px "Roboto Mono", monospace';
100
+ ctx.fillStyle = PANEL_CONFIG.ACCENT_COLOR;
101
+ ctx.fillText("Ring Composition:", xPos + 40, ringListY);
102
+ ringListY += 20;
103
+
104
+ planet.rings.forEach((ring, index) => {
105
+ const ringDisplayRadius = ring.radius * 0.5; // Scale down for display
106
+ const ringCenterY = ringListY + ringDisplayRadius + 5;
107
+
108
+ // Draw the ring visualization
109
+ ctx.save();
110
+ ctx.translate(xPos + 10, ringCenterY);
111
+ ring.draw(ctx);
112
+ ctx.restore();
113
+
114
+ // Draw ring parameters
115
+ const paramX = xPos + 40;
116
+ ctx.fillStyle = PANEL_CONFIG.TEXT_COLOR;
117
+ ctx.fillText(
118
+ `Ring ${index + 1}: r=${ring.radius.toFixed(1)}, th=${ring.thickness.toFixed(1)}, dotted=${ring.isDotted}`,
119
+ paramX,
120
+ ringCenterY - 5
121
+ );
122
+
123
+ ringListY += (ringDisplayRadius * 2) + 15;
124
+
125
+ // Draw separator line
126
+ if (index < planet.rings.length - 1) {
127
+ ctx.beginPath();
128
+ ctx.moveTo(paramX - 5, ringListY);
129
+ ctx.lineTo(PANEL_CONFIG.X + PANEL_CONFIG.WIDTH - PANEL_CONFIG.PADDING, ringListY);
130
+ ctx.strokeStyle = PANEL_CONFIG.BORDER_COLOR;
131
+ ctx.lineWidth = 0.5;
132
+ ctx.stroke();
133
+ ringListY += 10;
134
+ }
135
+ });
136
+ currentY = ringListY;
137
+ } else {
138
+ currentY += 80;
139
+ }
140
+ });
141
+
142
+ currentY += 20; // Space between categories
143
+ });
144
+
145
+ return currentY - startY;
146
+ }