@thewhateverapp/tile-sdk 0.14.9 → 0.14.11

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.
@@ -1,203 +0,0 @@
1
- 'use client';
2
- import React, { useCallback, useMemo } from 'react';
3
- import { Container, Graphics, Text } from '../../pixi/index.js';
4
- /**
5
- * Renders a single entity based on its kind
6
- */
7
- export function EntityRenderer({ state, debug = false }) {
8
- const { entity, x, y, rotation, scaleX, scaleY, alpha, fill } = state;
9
- const kind = entity.kind;
10
- // Parse fill color
11
- const fillColor = useMemo(() => {
12
- const color = fill ?? entity.render?.fill ?? '#ffffff';
13
- return parseInt(color.replace('#', ''), 16);
14
- }, [fill, entity.render?.fill]);
15
- // Parse stroke color
16
- const strokeColor = useMemo(() => {
17
- const color = entity.render?.stroke;
18
- if (!color)
19
- return undefined;
20
- return parseInt(color.replace('#', ''), 16);
21
- }, [entity.render?.stroke]);
22
- const strokeWidth = entity.render?.strokeWidth ?? 0;
23
- // Common container props
24
- const containerProps = {
25
- x,
26
- y,
27
- rotation,
28
- scale: { x: scaleX, y: scaleY },
29
- alpha,
30
- };
31
- switch (kind) {
32
- case 'rect':
33
- return (React.createElement(Container, { ...containerProps },
34
- React.createElement(RectEntity, { geom: entity.geom, fillColor: fillColor, strokeColor: strokeColor, strokeWidth: strokeWidth }),
35
- debug && React.createElement(DebugBounds, { geom: entity.geom })));
36
- case 'circle':
37
- return (React.createElement(Container, { ...containerProps },
38
- React.createElement(CircleEntity, { geom: entity.geom, fillColor: fillColor, strokeColor: strokeColor, strokeWidth: strokeWidth })));
39
- case 'poly':
40
- return (React.createElement(Container, { ...containerProps },
41
- React.createElement(PolyEntity, { geom: entity.geom, fillColor: fillColor, strokeColor: strokeColor, strokeWidth: strokeWidth })));
42
- case 'line':
43
- return (React.createElement(Container, { ...containerProps },
44
- React.createElement(LineEntity, { geom: entity.geom, strokeColor: strokeColor ?? fillColor })));
45
- case 'text':
46
- return (React.createElement(Container, { ...containerProps },
47
- React.createElement(TextEntity, { geom: entity.geom, fillColor: fillColor })));
48
- case 'sprite':
49
- return (React.createElement(Container, { ...containerProps },
50
- React.createElement(SpriteEntity, { geom: entity.geom })));
51
- case 'emitter':
52
- return (React.createElement(Container, { ...containerProps },
53
- React.createElement(EmitterEntity, { geom: entity.geom, fillColor: fillColor })));
54
- case 'group':
55
- // Groups are just containers, children are rendered separately
56
- return React.createElement(Container, { ...containerProps });
57
- default:
58
- console.warn(`Unknown entity kind: ${kind}`);
59
- return null;
60
- }
61
- }
62
- /**
63
- * Rect entity renderer
64
- */
65
- function RectEntity({ geom, fillColor, strokeColor, strokeWidth, }) {
66
- const draw = useCallback((g) => {
67
- g.clear();
68
- if (strokeColor !== undefined && strokeWidth > 0) {
69
- g.lineStyle(strokeWidth, strokeColor);
70
- }
71
- g.beginFill(fillColor);
72
- const anchorX = geom.w / 2;
73
- const anchorY = geom.h / 2;
74
- if (geom.cornerRadius && geom.cornerRadius > 0) {
75
- g.drawRoundedRect(-anchorX, -anchorY, geom.w, geom.h, geom.cornerRadius);
76
- }
77
- else {
78
- g.drawRect(-anchorX, -anchorY, geom.w, geom.h);
79
- }
80
- g.endFill();
81
- }, [geom.w, geom.h, geom.cornerRadius, fillColor, strokeColor, strokeWidth]);
82
- return React.createElement(Graphics, { draw: draw });
83
- }
84
- /**
85
- * Circle entity renderer
86
- */
87
- function CircleEntity({ geom, fillColor, strokeColor, strokeWidth, }) {
88
- const draw = useCallback((g) => {
89
- g.clear();
90
- if (strokeColor !== undefined && strokeWidth > 0) {
91
- g.lineStyle(strokeWidth, strokeColor);
92
- }
93
- g.beginFill(fillColor);
94
- g.drawCircle(0, 0, geom.r);
95
- g.endFill();
96
- }, [geom.r, fillColor, strokeColor, strokeWidth]);
97
- return React.createElement(Graphics, { draw: draw });
98
- }
99
- /**
100
- * Polygon entity renderer
101
- */
102
- function PolyEntity({ geom, fillColor, strokeColor, strokeWidth, }) {
103
- const draw = useCallback((g) => {
104
- g.clear();
105
- if (strokeColor !== undefined && strokeWidth > 0) {
106
- g.lineStyle(strokeWidth, strokeColor);
107
- }
108
- g.beginFill(fillColor);
109
- const points = geom.points;
110
- if (points.length < 3)
111
- return;
112
- g.moveTo(points[0][0], points[0][1]);
113
- for (let i = 1; i < points.length; i++) {
114
- g.lineTo(points[i][0], points[i][1]);
115
- }
116
- g.closePath();
117
- g.endFill();
118
- }, [geom.points, fillColor, strokeColor, strokeWidth]);
119
- return React.createElement(Graphics, { draw: draw });
120
- }
121
- /**
122
- * Line entity renderer
123
- */
124
- function LineEntity({ geom, strokeColor, }) {
125
- const draw = useCallback((g) => {
126
- g.clear();
127
- g.lineStyle(geom.lineWidth ?? 2, strokeColor);
128
- const points = geom.points;
129
- if (points.length < 2)
130
- return;
131
- g.moveTo(points[0][0], points[0][1]);
132
- for (let i = 1; i < points.length; i++) {
133
- g.lineTo(points[i][0], points[i][1]);
134
- }
135
- }, [geom.points, geom.lineWidth, strokeColor]);
136
- return React.createElement(Graphics, { draw: draw });
137
- }
138
- /**
139
- * Text entity renderer
140
- */
141
- function TextEntity({ geom, fillColor, }) {
142
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
- const style = useMemo(() => ({
144
- fontFamily: geom.fontFamily ?? 'Arial',
145
- fontSize: geom.fontSize ?? 16,
146
- fontWeight: geom.fontWeight ?? 'normal',
147
- fill: fillColor,
148
- align: geom.align ?? 'center',
149
- }), [geom.fontFamily, geom.fontSize, geom.fontWeight, geom.align, fillColor]);
150
- return (React.createElement(Text, { text: geom.text, style: style, anchor: { x: 0.5, y: 0.5 } }));
151
- }
152
- /**
153
- * Sprite entity renderer
154
- */
155
- function SpriteEntity({ geom }) {
156
- // For now, just render a placeholder
157
- // Full sprite loading requires texture management
158
- const draw = useCallback((g) => {
159
- g.clear();
160
- g.beginFill(0x888888);
161
- const w = geom.w ?? 32;
162
- const h = geom.h ?? 32;
163
- g.drawRect(-w / 2, -h / 2, w, h);
164
- g.endFill();
165
- // Draw X to indicate missing sprite
166
- g.lineStyle(2, 0xff0000);
167
- g.moveTo(-w / 2, -h / 2);
168
- g.lineTo(w / 2, h / 2);
169
- g.moveTo(w / 2, -h / 2);
170
- g.lineTo(-w / 2, h / 2);
171
- }, [geom.w, geom.h]);
172
- // TODO: Load actual sprite from geom.src
173
- return React.createElement(Graphics, { draw: draw });
174
- }
175
- /**
176
- * Particle emitter entity renderer
177
- * This is a simplified version - full particle system is in effects/
178
- */
179
- function EmitterEntity({ geom, fillColor, }) {
180
- // For now, just draw a marker for the emitter
181
- const draw = useCallback((g) => {
182
- g.clear();
183
- g.beginFill(fillColor, 0.3);
184
- g.drawCircle(0, 0, 10);
185
- g.endFill();
186
- // Draw emitter indicator
187
- g.lineStyle(1, fillColor);
188
- g.drawCircle(0, 0, 15);
189
- }, [fillColor]);
190
- // TODO: Implement full particle system
191
- return React.createElement(Graphics, { draw: draw });
192
- }
193
- /**
194
- * Debug bounds renderer
195
- */
196
- function DebugBounds({ geom }) {
197
- const draw = useCallback((g) => {
198
- g.clear();
199
- g.lineStyle(1, 0x00ff00, 0.5);
200
- g.drawRect(-geom.w / 2, -geom.h / 2, geom.w, geom.h);
201
- }, [geom.w, geom.h]);
202
- return React.createElement(Graphics, { draw: draw });
203
- }