-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
173 lines (173 loc) · 7.58 KB
/
App.js
File metadata and controls
173 lines (173 loc) · 7.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
var _this = this;
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import React, { useEffect, useRef, useState } from 'react';
import { Game } from './Game.js';
import { DOFControls } from './DOFControls.js';
import { ObjectListPanel } from './ObjectListPanel.js';
import { TransformControlsPanel } from './TransformControlsPanel.js'; // Import the new panel
export var App = function() {
var gameCanvasContainerRef = useRef(null);
var gameInstanceRef = useRef(null);
var _useState = _sliced_to_array(useState(false), 2), gameReady = _useState[0], setGameReady = _useState[1];
var _useState1 = _sliced_to_array(useState([]), 2), interactiveObjects = _useState1[0], setInteractiveObjects = _useState1[1];
var _useState2 = _sliced_to_array(useState(null), 2), selectedObjectForTransform = _useState2[0], setSelectedObjectForTransform = _useState2[1];
useEffect(function() {
if (gameCanvasContainerRef.current && !gameInstanceRef.current) {
var game = new Game(gameCanvasContainerRef.current);
game.start();
gameInstanceRef.current = game;
setGameReady(true);
// Expose draggableObjects for the panel
// Ensure game.draggableObjects is populated by the time this runs
// Game._setup() should populate it.
if (game.draggableObjects) {
setInteractiveObjects(game.draggableObjects);
}
// Setup a callback for when game selects an object
if (typeof game.setOnObjectSelectedCallback === 'function') {
game.setOnObjectSelectedCallback(function(object) {
setSelectedObjectForTransform(object);
});
// Setup a callback for when game object is transformed by gizmo
if (typeof game.setOnObjectTransformedByGizmoCallback === 'function') {
game.setOnObjectTransformedByGizmoCallback(function(object) {
// This will force TransformControlsPanel to re-read object's new transform
setSelectedObjectForTransform(null); // Force unmount/remount or key change
setTimeout(function() {
return setSelectedObjectForTransform(object);
}, 0); // Re-select to refresh panel
});
}
}
}
return function() {
if (gameInstanceRef.current) {
if (typeof gameInstanceRef.current.dispose === 'function') {
gameInstanceRef.current.dispose();
} else {
// Fallback cleanup if dispose isn't fully implemented or available
if (gameInstanceRef.current.renderer && gameInstanceRef.current.renderer.domElement.parentNode) {
gameInstanceRef.current.renderer.domElement.parentNode.removeChild(gameInstanceRef.current.renderer.domElement);
}
if (gameInstanceRef.current.animationFrameId) {
cancelAnimationFrame(gameInstanceRef.current.animationFrameId);
}
}
gameInstanceRef.current = null;
setSelectedObjectForTransform(null); // Clear selection on dispose
}
};
}, []); // Empty dependency array: runs once on mount, cleans up on unmount
var handleObjectSelect = function(object) {
setSelectedObjectForTransform(object);
if (gameInstanceRef.current && typeof gameInstanceRef.current.selectObjectFromPanel === 'function') {
gameInstanceRef.current.selectObjectFromPanel(object);
}
};
var handleTransformChange = function(object, type, value) {
if (gameInstanceRef.current && typeof gameInstanceRef.current.updateObjectTransform === 'function') {
gameInstanceRef.current.updateObjectTransform(object, type, value);
}
};
var handleGizmoModeChange = function(mode) {
if (gameInstanceRef.current && typeof gameInstanceRef.current.setTransformMode === 'function') {
gameInstanceRef.current.setTransformMode(mode);
}
};
return /*#__PURE__*/ _jsxDEV("div", {
style: {
width: '100%',
height: '100%',
position: 'relative',
margin: 0,
overflow: 'hidden'
},
children: [
/*#__PURE__*/ _jsxDEV("div", {
ref: gameCanvasContainerRef,
style: {
width: '100%',
height: '100%'
}
}, void 0, false, {
fileName: "App.jsx",
lineNumber: 76,
columnNumber: 7
}, _this),
gameReady && /*#__PURE__*/ _jsxDEV(DOFControls, {
gameInstanceRef: gameInstanceRef
}, void 0, false, {
fileName: "App.jsx",
lineNumber: 77,
columnNumber: 21
}, _this),
gameReady && interactiveObjects.length > 0 && /*#__PURE__*/ _jsxDEV(ObjectListPanel, {
objects: interactiveObjects,
onObjectSelect: handleObjectSelect
}, void 0, false, {
fileName: "App.jsx",
lineNumber: 79,
columnNumber: 9
}, _this),
gameReady && selectedObjectForTransform && /*#__PURE__*/ _jsxDEV(TransformControlsPanel, {
selectedObject: selectedObjectForTransform,
onTransformChange: handleTransformChange,
onModeChange: handleGizmoModeChange
}, void 0, false, {
fileName: "App.jsx",
lineNumber: 85,
columnNumber: 9
}, _this)
]
}, void 0, true, {
fileName: "App.jsx",
lineNumber: 75,
columnNumber: 5
}, _this);
};