@flare-engine/shapes 0.2.1 → 0.3.1
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.
- package/LICENSE +201 -21
- package/NOTICE +2 -0
- package/README.md +29 -16
- package/dist/index.d.mts +92 -99
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +92 -99
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +363 -382
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +355 -348
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -8
package/dist/index.js
CHANGED
|
@@ -1,431 +1,412 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
applyFriendlyGlow: () => applyFriendlyGlow,
|
|
24
|
-
applyHazardGlow: () => applyHazardGlow,
|
|
25
|
-
argbTo: () => argbTo,
|
|
26
|
-
drawShape: () => drawShape,
|
|
27
|
-
friendlyGlowArgb: () => friendlyGlowArgb,
|
|
28
|
-
hazardGlowArgb: () => hazardGlowArgb,
|
|
29
|
-
shapeBoundsRadius: () => shapeBoundsRadius,
|
|
30
|
-
singleShapeRadius: () => singleShapeRadius
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(index_exports);
|
|
33
|
-
|
|
34
|
-
// src/bounds.ts
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/bounds.ts
|
|
3
|
+
/**
|
|
4
|
+
* Approximate bounding radius for a single primitive. Used to size glow
|
|
5
|
+
* rings and atlas tiles. Returned values are deliberately a touch generous
|
|
6
|
+
* to avoid clipping.
|
|
7
|
+
*/
|
|
35
8
|
function singleShapeRadius(spec) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
9
|
+
switch (spec.kind) {
|
|
10
|
+
case "circle":
|
|
11
|
+
case "ring":
|
|
12
|
+
case "ngon": return spec.r;
|
|
13
|
+
case "triangle": return spec.size;
|
|
14
|
+
case "star": return spec.rOuter;
|
|
15
|
+
case "rect":
|
|
16
|
+
case "gradient-rect": return Math.max(spec.w, spec.h) * .6;
|
|
17
|
+
case "polyline": {
|
|
18
|
+
let max = 0;
|
|
19
|
+
for (let i = 0; i < spec.points.length; i += 2) {
|
|
20
|
+
const px = spec.points[i] ?? 0;
|
|
21
|
+
const py = spec.points[i + 1] ?? 0;
|
|
22
|
+
const m = Math.hypot(px, py);
|
|
23
|
+
if (m > max) max = m;
|
|
24
|
+
}
|
|
25
|
+
return max + (spec.strokeWidth ?? 1);
|
|
26
|
+
}
|
|
27
|
+
case "arc": return spec.r;
|
|
28
|
+
case "annulus": return spec.rOuter;
|
|
29
|
+
case "trapezoid": return Math.max(spec.topW, spec.botW, spec.h) * .6;
|
|
30
|
+
case "path": return spec.boundsR;
|
|
31
|
+
case "ship": {
|
|
32
|
+
const { hull, weapons, engine } = spec;
|
|
33
|
+
let max = Math.hypot(hull.ox ?? 0, hull.oy ?? 0) + singleShapeRadius(hull);
|
|
34
|
+
for (let i = 0; i < weapons.length; i++) {
|
|
35
|
+
const w = weapons[i];
|
|
36
|
+
if (w === void 0) continue;
|
|
37
|
+
const reach = Math.hypot(w.ox ?? 0, w.oy ?? 0) + singleShapeRadius(w);
|
|
38
|
+
if (reach > max) max = reach;
|
|
39
|
+
}
|
|
40
|
+
const engineReach = Math.hypot(engine.ox ?? 0, engine.oy ?? 0) + engine.size * .6;
|
|
41
|
+
if (engineReach > max) max = engineReach;
|
|
42
|
+
return max;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
69
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Compute axis-aligned bounding radius for a shape composition. Used to
|
|
48
|
+
* size atlas tiles. Returns the max half-extent from origin across all
|
|
49
|
+
* shapes (including their `ox`/`oy` offsets and stroke widths).
|
|
50
|
+
*/
|
|
70
51
|
function shapeBoundsRadius(specs) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
52
|
+
let max = 0;
|
|
53
|
+
for (const s of specs) {
|
|
54
|
+
const ox = s.ox ?? 0;
|
|
55
|
+
const oy = s.oy ?? 0;
|
|
56
|
+
const r = boundsR(s);
|
|
57
|
+
const reach = Math.hypot(ox, oy) + r + 2;
|
|
58
|
+
if (reach > max) max = reach;
|
|
59
|
+
}
|
|
60
|
+
return Math.max(4, max);
|
|
80
61
|
}
|
|
62
|
+
/** Tighter atlas-tile-sizing radius (rect/gradient-rect use 0.75 to fit corners). */
|
|
81
63
|
function boundsR(spec) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
64
|
+
switch (spec.kind) {
|
|
65
|
+
case "rect":
|
|
66
|
+
case "gradient-rect": return Math.max(spec.w, spec.h) * .75;
|
|
67
|
+
case "trapezoid": return Math.max(spec.topW, spec.botW, spec.h) * .75;
|
|
68
|
+
case "ship": return shapeBoundsRadius([
|
|
69
|
+
spec.hull,
|
|
70
|
+
...spec.weapons,
|
|
71
|
+
{
|
|
72
|
+
kind: "rect",
|
|
73
|
+
w: spec.engine.size,
|
|
74
|
+
h: spec.engine.size,
|
|
75
|
+
ox: spec.engine.ox,
|
|
76
|
+
oy: spec.engine.oy
|
|
77
|
+
}
|
|
78
|
+
]);
|
|
79
|
+
default: return singleShapeRadius(spec);
|
|
80
|
+
}
|
|
93
81
|
}
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/draw.ts
|
|
84
|
+
/** ARGB for safe #6FA66B at α ≈ 0.25 (0x40 / 255). */
|
|
96
85
|
function friendlyGlowArgb() {
|
|
97
|
-
|
|
86
|
+
return 1081058923;
|
|
98
87
|
}
|
|
88
|
+
/** ARGB for hazardOrange #E84B2A at α ≈ 0.6 (0x99 / 255). */
|
|
99
89
|
function hazardGlowArgb() {
|
|
100
|
-
|
|
90
|
+
return -1712829654;
|
|
101
91
|
}
|
|
102
92
|
function applyFriendlyGlow(_Skia, canvas, paint, cx, cy, r) {
|
|
103
|
-
|
|
104
|
-
|
|
93
|
+
applyStroke(paint, friendlyGlowArgb(), 3);
|
|
94
|
+
canvas.drawCircle(cx, cy, r + 4, paint);
|
|
105
95
|
}
|
|
106
96
|
function applyHazardGlow(_Skia, canvas, paint, cx, cy, r) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
canvas.drawCircle(cx, cy, r + 2, paint);
|
|
97
|
+
applyStroke(paint, hazardGlowArgb(), .5);
|
|
98
|
+
canvas.drawCircle(cx, cy, r + 1, paint);
|
|
99
|
+
canvas.drawCircle(cx, cy, r + 2, paint);
|
|
111
100
|
}
|
|
112
|
-
|
|
101
|
+
const COLOR = /* @__PURE__ */ new Float32Array(4);
|
|
113
102
|
function argbTo(out, argb) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
103
|
+
out[0] = (argb >>> 16 & 255) / 255;
|
|
104
|
+
out[1] = (argb >>> 8 & 255) / 255;
|
|
105
|
+
out[2] = (argb & 255) / 255;
|
|
106
|
+
out[3] = (argb >>> 24 & 255) / 255;
|
|
118
107
|
}
|
|
119
108
|
function applyFill(paint, argb) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
argbTo(COLOR, argb);
|
|
110
|
+
paint.setColor(COLOR);
|
|
111
|
+
paint.setStyle(0);
|
|
123
112
|
}
|
|
124
113
|
function applyStroke(paint, argb, width) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
114
|
+
argbTo(COLOR, argb);
|
|
115
|
+
paint.setColor(COLOR);
|
|
116
|
+
paint.setStyle(1);
|
|
117
|
+
paint.setStrokeWidth(width);
|
|
129
118
|
}
|
|
130
119
|
function drawShape(Skia, canvas, paint, spec, x, y, rot) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return;
|
|
189
|
-
case "ship":
|
|
190
|
-
drawShip(Skia, canvas, paint, spec, cx, cy, r);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
120
|
+
const cx = x + (spec.ox ?? 0);
|
|
121
|
+
const cy = y + (spec.oy ?? 0);
|
|
122
|
+
const r = rot + (spec.rot ?? 0);
|
|
123
|
+
if (spec.glow !== void 0) {
|
|
124
|
+
const gr = singleShapeRadius(spec);
|
|
125
|
+
if (spec.glow === "friendly") applyFriendlyGlow(Skia, canvas, paint, cx, cy, gr);
|
|
126
|
+
else applyHazardGlow(Skia, canvas, paint, cx, cy, gr);
|
|
127
|
+
}
|
|
128
|
+
switch (spec.kind) {
|
|
129
|
+
case "circle":
|
|
130
|
+
if (spec.fill !== void 0) {
|
|
131
|
+
applyFill(paint, spec.fill);
|
|
132
|
+
canvas.drawCircle(cx, cy, spec.r, paint);
|
|
133
|
+
}
|
|
134
|
+
if (spec.stroke !== void 0) {
|
|
135
|
+
applyStroke(paint, spec.stroke, spec.strokeWidth ?? 1);
|
|
136
|
+
canvas.drawCircle(cx, cy, spec.r, paint);
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
case "ring":
|
|
140
|
+
applyStroke(paint, spec.stroke ?? 4278190080, spec.strokeWidth ?? 1);
|
|
141
|
+
canvas.drawCircle(cx, cy, spec.r, paint);
|
|
142
|
+
return;
|
|
143
|
+
case "rect":
|
|
144
|
+
drawRect(Skia, canvas, paint, spec, cx, cy, r);
|
|
145
|
+
return;
|
|
146
|
+
case "triangle":
|
|
147
|
+
drawTriangle(Skia, canvas, paint, spec, cx, cy, r);
|
|
148
|
+
return;
|
|
149
|
+
case "ngon":
|
|
150
|
+
drawNgon(Skia, canvas, paint, spec, cx, cy, r);
|
|
151
|
+
return;
|
|
152
|
+
case "star":
|
|
153
|
+
drawStar(Skia, canvas, paint, spec, cx, cy, r);
|
|
154
|
+
return;
|
|
155
|
+
case "polyline":
|
|
156
|
+
drawPolyline(Skia, canvas, paint, spec, cx, cy, r);
|
|
157
|
+
return;
|
|
158
|
+
case "gradient-rect":
|
|
159
|
+
drawGradientRect(Skia, canvas, paint, spec, cx, cy, r);
|
|
160
|
+
return;
|
|
161
|
+
case "arc":
|
|
162
|
+
drawArc(Skia, canvas, paint, spec, cx, cy, r);
|
|
163
|
+
return;
|
|
164
|
+
case "annulus":
|
|
165
|
+
drawAnnulus(Skia, canvas, paint, spec, cx, cy, r);
|
|
166
|
+
return;
|
|
167
|
+
case "trapezoid":
|
|
168
|
+
drawTrapezoid(Skia, canvas, paint, spec, cx, cy, r);
|
|
169
|
+
return;
|
|
170
|
+
case "path":
|
|
171
|
+
drawPath(Skia, canvas, paint, spec, cx, cy, r);
|
|
172
|
+
return;
|
|
173
|
+
case "ship":
|
|
174
|
+
drawShip(Skia, canvas, paint, spec, cx, cy, r);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
193
177
|
}
|
|
194
178
|
function drawRect(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
179
|
+
canvas.save();
|
|
180
|
+
canvas.translate(cx, cy);
|
|
181
|
+
if (rot !== 0) canvas.rotate(rot * 180 / Math.PI, 0, 0);
|
|
182
|
+
const rect = Skia.XYWHRect(-spec.w / 2, -spec.h / 2, spec.w, spec.h);
|
|
183
|
+
if (spec.fill !== void 0) {
|
|
184
|
+
applyFill(paint, spec.fill);
|
|
185
|
+
canvas.drawRect(rect, paint);
|
|
186
|
+
}
|
|
187
|
+
if (spec.stroke !== void 0) {
|
|
188
|
+
applyStroke(paint, spec.stroke, spec.strokeWidth ?? 1);
|
|
189
|
+
canvas.drawRect(rect, paint);
|
|
190
|
+
}
|
|
191
|
+
canvas.restore();
|
|
208
192
|
}
|
|
209
193
|
function drawTriangle(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
194
|
+
const s = spec.size;
|
|
195
|
+
const path = Skia.Path.Make();
|
|
196
|
+
path.moveTo(0, -s);
|
|
197
|
+
path.lineTo(-s * .6, s * .4);
|
|
198
|
+
path.lineTo(s * .6, s * .4);
|
|
199
|
+
path.close();
|
|
200
|
+
canvas.save();
|
|
201
|
+
canvas.translate(cx, cy);
|
|
202
|
+
if (rot !== 0) canvas.rotate(rot * 180 / Math.PI, 0, 0);
|
|
203
|
+
if (spec.fill !== void 0) {
|
|
204
|
+
applyFill(paint, spec.fill);
|
|
205
|
+
canvas.drawPath(path, paint);
|
|
206
|
+
}
|
|
207
|
+
if (spec.stroke !== void 0) {
|
|
208
|
+
applyStroke(paint, spec.stroke, spec.strokeWidth ?? 1);
|
|
209
|
+
canvas.drawPath(path, paint);
|
|
210
|
+
}
|
|
211
|
+
canvas.restore();
|
|
228
212
|
}
|
|
229
213
|
function drawNgon(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
214
|
+
const path = Skia.Path.Make();
|
|
215
|
+
for (let i = 0; i < spec.n; i++) {
|
|
216
|
+
const a = i / spec.n * Math.PI * 2 - Math.PI / 2;
|
|
217
|
+
const px = Math.cos(a) * spec.r;
|
|
218
|
+
const py = Math.sin(a) * spec.r;
|
|
219
|
+
if (i === 0) path.moveTo(px, py);
|
|
220
|
+
else path.lineTo(px, py);
|
|
221
|
+
}
|
|
222
|
+
path.close();
|
|
223
|
+
canvas.save();
|
|
224
|
+
canvas.translate(cx, cy);
|
|
225
|
+
if (rot !== 0) canvas.rotate(rot * 180 / Math.PI, 0, 0);
|
|
226
|
+
if (spec.fill !== void 0) {
|
|
227
|
+
applyFill(paint, spec.fill);
|
|
228
|
+
canvas.drawPath(path, paint);
|
|
229
|
+
}
|
|
230
|
+
if (spec.stroke !== void 0) {
|
|
231
|
+
applyStroke(paint, spec.stroke, spec.strokeWidth ?? 1);
|
|
232
|
+
canvas.drawPath(path, paint);
|
|
233
|
+
}
|
|
234
|
+
canvas.restore();
|
|
251
235
|
}
|
|
252
236
|
function drawStar(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
237
|
+
const path = Skia.Path.Make();
|
|
238
|
+
const total = spec.points * 2;
|
|
239
|
+
for (let i = 0; i < total; i++) {
|
|
240
|
+
const a = i / total * Math.PI * 2 - Math.PI / 2;
|
|
241
|
+
const r = i % 2 === 0 ? spec.rOuter : spec.rInner;
|
|
242
|
+
const px = Math.cos(a) * r;
|
|
243
|
+
const py = Math.sin(a) * r;
|
|
244
|
+
if (i === 0) path.moveTo(px, py);
|
|
245
|
+
else path.lineTo(px, py);
|
|
246
|
+
}
|
|
247
|
+
path.close();
|
|
248
|
+
canvas.save();
|
|
249
|
+
canvas.translate(cx, cy);
|
|
250
|
+
if (rot !== 0) canvas.rotate(rot * 180 / Math.PI, 0, 0);
|
|
251
|
+
if (spec.fill !== void 0) {
|
|
252
|
+
applyFill(paint, spec.fill);
|
|
253
|
+
canvas.drawPath(path, paint);
|
|
254
|
+
}
|
|
255
|
+
if (spec.stroke !== void 0) {
|
|
256
|
+
applyStroke(paint, spec.stroke, spec.strokeWidth ?? 1);
|
|
257
|
+
canvas.drawPath(path, paint);
|
|
258
|
+
}
|
|
259
|
+
canvas.restore();
|
|
276
260
|
}
|
|
277
261
|
function drawPolyline(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
canvas.drawPath(path, paint);
|
|
290
|
-
canvas.restore();
|
|
262
|
+
const pts = spec.points;
|
|
263
|
+
if (pts.length < 4) return;
|
|
264
|
+
const path = Skia.Path.Make();
|
|
265
|
+
path.moveTo(pts[0] ?? 0, pts[1] ?? 0);
|
|
266
|
+
for (let i = 2; i < pts.length; i += 2) path.lineTo(pts[i] ?? 0, pts[i + 1] ?? 0);
|
|
267
|
+
canvas.save();
|
|
268
|
+
canvas.translate(cx, cy);
|
|
269
|
+
if (rot !== 0) canvas.rotate(rot * 180 / Math.PI, 0, 0);
|
|
270
|
+
applyStroke(paint, spec.stroke ?? 4278190080, spec.strokeWidth ?? 1);
|
|
271
|
+
canvas.drawPath(path, paint);
|
|
272
|
+
canvas.restore();
|
|
291
273
|
}
|
|
292
274
|
function drawGradientRect(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
275
|
+
canvas.save();
|
|
276
|
+
canvas.translate(cx, cy);
|
|
277
|
+
if (rot !== 0) canvas.rotate(rot * 180 / Math.PI, 0, 0);
|
|
278
|
+
const half = spec.axis === 1 ? spec.h / 2 : spec.w / 2;
|
|
279
|
+
if (spec.axis === 1) {
|
|
280
|
+
applyFill(paint, spec.colorA);
|
|
281
|
+
canvas.drawRect(Skia.XYWHRect(-spec.w / 2, -spec.h / 2, spec.w, half), paint);
|
|
282
|
+
applyFill(paint, spec.colorB);
|
|
283
|
+
canvas.drawRect(Skia.XYWHRect(-spec.w / 2, 0, spec.w, half), paint);
|
|
284
|
+
} else {
|
|
285
|
+
applyFill(paint, spec.colorA);
|
|
286
|
+
canvas.drawRect(Skia.XYWHRect(-spec.w / 2, -spec.h / 2, half, spec.h), paint);
|
|
287
|
+
applyFill(paint, spec.colorB);
|
|
288
|
+
canvas.drawRect(Skia.XYWHRect(0, -spec.h / 2, half, spec.h), paint);
|
|
289
|
+
}
|
|
290
|
+
canvas.restore();
|
|
309
291
|
}
|
|
310
292
|
function radToDeg(rad) {
|
|
311
|
-
|
|
293
|
+
return rad * 180 / Math.PI;
|
|
312
294
|
}
|
|
313
295
|
function drawArc(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
canvas.restore();
|
|
296
|
+
const path = Skia.Path.Make();
|
|
297
|
+
const oval = Skia.XYWHRect(-spec.r, -spec.r, spec.r * 2, spec.r * 2);
|
|
298
|
+
const startDeg = radToDeg(spec.startAngle);
|
|
299
|
+
const sweepDeg = radToDeg(spec.endAngle - spec.startAngle);
|
|
300
|
+
if (spec.sector === true) {
|
|
301
|
+
path.moveTo(0, 0);
|
|
302
|
+
path.addArc(oval, startDeg, sweepDeg);
|
|
303
|
+
path.close();
|
|
304
|
+
} else path.addArc(oval, startDeg, sweepDeg);
|
|
305
|
+
canvas.save();
|
|
306
|
+
canvas.translate(cx, cy);
|
|
307
|
+
if (rot !== 0) canvas.rotate(radToDeg(rot), 0, 0);
|
|
308
|
+
if (spec.fill !== void 0) {
|
|
309
|
+
applyFill(paint, spec.fill);
|
|
310
|
+
canvas.drawPath(path, paint);
|
|
311
|
+
}
|
|
312
|
+
if (spec.stroke !== void 0) {
|
|
313
|
+
applyStroke(paint, spec.stroke, spec.strokeWidth ?? 1);
|
|
314
|
+
canvas.drawPath(path, paint);
|
|
315
|
+
}
|
|
316
|
+
canvas.restore();
|
|
337
317
|
}
|
|
338
318
|
function drawAnnulus(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
319
|
+
const midR = (spec.rOuter + spec.rInner) / 2;
|
|
320
|
+
const thickness = spec.rOuter - spec.rInner;
|
|
321
|
+
const ringColor = spec.fill ?? spec.stroke ?? 4278190080;
|
|
322
|
+
canvas.save();
|
|
323
|
+
canvas.translate(cx, cy);
|
|
324
|
+
if (rot !== 0) canvas.rotate(radToDeg(rot), 0, 0);
|
|
325
|
+
if (spec.startAngle !== void 0 && spec.endAngle !== void 0) {
|
|
326
|
+
const path = Skia.Path.Make();
|
|
327
|
+
const oval = Skia.XYWHRect(-midR, -midR, midR * 2, midR * 2);
|
|
328
|
+
path.addArc(oval, radToDeg(spec.startAngle), radToDeg(spec.endAngle - spec.startAngle));
|
|
329
|
+
applyStroke(paint, ringColor, thickness);
|
|
330
|
+
canvas.drawPath(path, paint);
|
|
331
|
+
} else {
|
|
332
|
+
applyStroke(paint, ringColor, thickness);
|
|
333
|
+
canvas.drawCircle(0, 0, midR, paint);
|
|
334
|
+
}
|
|
335
|
+
canvas.restore();
|
|
356
336
|
}
|
|
357
337
|
function drawTrapezoid(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
338
|
+
const path = Skia.Path.Make();
|
|
339
|
+
const halfTopW = spec.topW / 2;
|
|
340
|
+
const halfBotW = spec.botW / 2;
|
|
341
|
+
const halfH = spec.h / 2;
|
|
342
|
+
path.moveTo(-halfTopW, -halfH);
|
|
343
|
+
path.lineTo(halfTopW, -halfH);
|
|
344
|
+
path.lineTo(halfBotW, halfH);
|
|
345
|
+
path.lineTo(-halfBotW, halfH);
|
|
346
|
+
path.close();
|
|
347
|
+
canvas.save();
|
|
348
|
+
canvas.translate(cx, cy);
|
|
349
|
+
if (rot !== 0) canvas.rotate(radToDeg(rot), 0, 0);
|
|
350
|
+
if (spec.fill !== void 0) {
|
|
351
|
+
applyFill(paint, spec.fill);
|
|
352
|
+
canvas.drawPath(path, paint);
|
|
353
|
+
}
|
|
354
|
+
if (spec.stroke !== void 0) {
|
|
355
|
+
applyStroke(paint, spec.stroke, spec.strokeWidth ?? 1);
|
|
356
|
+
canvas.drawPath(path, paint);
|
|
357
|
+
}
|
|
358
|
+
canvas.restore();
|
|
379
359
|
}
|
|
380
360
|
function drawPath(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
361
|
+
const path = Skia.Path.MakeFromSVGString(spec.d);
|
|
362
|
+
if (path === null) return;
|
|
363
|
+
canvas.save();
|
|
364
|
+
canvas.translate(cx, cy);
|
|
365
|
+
if (rot !== 0) canvas.rotate(radToDeg(rot), 0, 0);
|
|
366
|
+
if (spec.fill !== void 0) {
|
|
367
|
+
applyFill(paint, spec.fill);
|
|
368
|
+
canvas.drawPath(path, paint);
|
|
369
|
+
}
|
|
370
|
+
if (spec.stroke !== void 0) {
|
|
371
|
+
applyStroke(paint, spec.stroke, spec.strokeWidth ?? 1);
|
|
372
|
+
canvas.drawPath(path, paint);
|
|
373
|
+
}
|
|
374
|
+
canvas.restore();
|
|
395
375
|
}
|
|
396
376
|
function drawSquare(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
drawRect(Skia, canvas, paint, rectSpec, cx, cy, rot);
|
|
377
|
+
drawRect(Skia, canvas, paint, {
|
|
378
|
+
kind: "rect",
|
|
379
|
+
w: spec.size,
|
|
380
|
+
h: spec.size,
|
|
381
|
+
fill: spec.fill,
|
|
382
|
+
stroke: spec.stroke,
|
|
383
|
+
strokeWidth: spec.strokeWidth,
|
|
384
|
+
ox: spec.ox,
|
|
385
|
+
oy: spec.oy,
|
|
386
|
+
rot: spec.rot
|
|
387
|
+
}, cx, cy, rot);
|
|
409
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Draw a ShipSpec by painting engine → hull → weapons (engine deepest,
|
|
391
|
+
* weapons foremost — painter's algorithm). Zero allocation in the weapons
|
|
392
|
+
* loop: classic indexed for-loop over the readonly array.
|
|
393
|
+
*/
|
|
410
394
|
function drawShip(Skia, canvas, paint, spec, cx, cy, rot) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
}
|
|
395
|
+
drawSquare(Skia, canvas, paint, spec.engine, cx, cy, rot);
|
|
396
|
+
drawShape(Skia, canvas, paint, spec.hull, cx, cy, rot);
|
|
397
|
+
for (let i = 0; i < spec.weapons.length; i++) {
|
|
398
|
+
const w = spec.weapons[i];
|
|
399
|
+
if (w !== void 0) drawShape(Skia, canvas, paint, w, cx, cy, rot);
|
|
400
|
+
}
|
|
419
401
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
});
|
|
402
|
+
//#endregion
|
|
403
|
+
exports.applyFriendlyGlow = applyFriendlyGlow;
|
|
404
|
+
exports.applyHazardGlow = applyHazardGlow;
|
|
405
|
+
exports.argbTo = argbTo;
|
|
406
|
+
exports.drawShape = drawShape;
|
|
407
|
+
exports.friendlyGlowArgb = friendlyGlowArgb;
|
|
408
|
+
exports.hazardGlowArgb = hazardGlowArgb;
|
|
409
|
+
exports.shapeBoundsRadius = shapeBoundsRadius;
|
|
410
|
+
exports.singleShapeRadius = singleShapeRadius;
|
|
411
|
+
|
|
431
412
|
//# sourceMappingURL=index.js.map
|