@@ -99,19 +99,34 @@ export class ScriptExecutor {
9999 // Parse regular function declarations
100100 while ( ( match = functionRegex . exec ( cleanCode ) ) !== null ) {
101101 const [ , functionName , functionBody ] = match ;
102- result [ functionName as keyof IParsedScript ] = functionBody . trim ( ) ;
102+ const body = functionBody . trim ( ) ;
103+ if ( functionName === 'onStart' ) result . onStart = body ;
104+ if ( functionName === 'onUpdate' ) result . onUpdate = body ;
105+ if ( functionName === 'onDestroy' ) result . onDestroy = body ;
106+ if ( functionName === 'onEnable' ) result . onEnable = body ;
107+ if ( functionName === 'onDisable' ) result . onDisable = body ;
103108 }
104109
105110 // Parse arrow function declarations
106111 while ( ( match = arrowFunctionRegex . exec ( cleanCode ) ) !== null ) {
107112 const [ , functionName , functionBody ] = match ;
108- result [ functionName as keyof IParsedScript ] = functionBody . trim ( ) ;
113+ const body = functionBody . trim ( ) ;
114+ if ( functionName === 'onStart' ) result . onStart = body ;
115+ if ( functionName === 'onUpdate' ) result . onUpdate = body ;
116+ if ( functionName === 'onDestroy' ) result . onDestroy = body ;
117+ if ( functionName === 'onEnable' ) result . onEnable = body ;
118+ if ( functionName === 'onDisable' ) result . onDisable = body ;
109119 }
110120
111121 // Parse simple arrow function assignments
112122 while ( ( match = simpleArrowRegex . exec ( cleanCode ) ) !== null ) {
113123 const [ , functionName , functionBody ] = match ;
114- result [ functionName as keyof IParsedScript ] = functionBody . trim ( ) ;
124+ const body = functionBody . trim ( ) ;
125+ if ( functionName === 'onStart' ) result . onStart = body ;
126+ if ( functionName === 'onUpdate' ) result . onUpdate = body ;
127+ if ( functionName === 'onDestroy' ) result . onDestroy = body ;
128+ if ( functionName === 'onEnable' ) result . onEnable = body ;
129+ if ( functionName === 'onDisable' ) result . onDisable = body ;
115130 }
116131
117132 console . log ( '[ScriptExecutor] Parsed script functions:' , {
@@ -172,7 +187,10 @@ export class ScriptExecutor {
172187 const axis = match [ 1 ] as 'x' | 'y' | 'z' ;
173188 const value = parseFloat ( match [ 2 ] ) ;
174189 if ( ! isNaN ( value ) ) {
175- context . entity . position [ axis ] = value ;
190+ const [ px , py , pz ] = context . entity . transform . position ;
191+ if ( axis === 'x' ) context . entity . transform . setPosition ( value , py , pz ) ;
192+ if ( axis === 'y' ) context . entity . transform . setPosition ( px , value , pz ) ;
193+ if ( axis === 'z' ) context . entity . transform . setPosition ( px , py , value ) ;
176194 }
177195 }
178196 }
@@ -190,12 +208,19 @@ export class ScriptExecutor {
190208 const operator = match [ 2 ] ;
191209 const value = parseFloat ( match [ 3 ] ) ;
192210 if ( ! isNaN ( value ) ) {
211+ const [ rx , ry , rz ] = context . entity . transform . rotation ;
193212 if ( operator === '=' ) {
194- context . entity . rotation [ axis ] = value ;
213+ if ( axis === 'x' ) context . entity . transform . setRotation ( value , ry , rz ) ;
214+ if ( axis === 'y' ) context . entity . transform . setRotation ( rx , value , rz ) ;
215+ if ( axis === 'z' ) context . entity . transform . setRotation ( rx , ry , value ) ;
195216 } else if ( operator === '+' ) {
196- context . entity . rotation [ axis ] += value ;
217+ if ( axis === 'x' ) context . entity . transform . setRotation ( rx + value , ry , rz ) ;
218+ if ( axis === 'y' ) context . entity . transform . setRotation ( rx , ry + value , rz ) ;
219+ if ( axis === 'z' ) context . entity . transform . setRotation ( rx , ry , rz + value ) ;
197220 } else if ( operator === '-' ) {
198- context . entity . rotation [ axis ] -= value ;
221+ if ( axis === 'x' ) context . entity . transform . setRotation ( rx - value , ry , rz ) ;
222+ if ( axis === 'y' ) context . entity . transform . setRotation ( rx , ry - value , rz ) ;
223+ if ( axis === 'z' ) context . entity . transform . setRotation ( rx , ry , rz - value ) ;
199224 }
200225 }
201226 }
@@ -214,7 +239,11 @@ export class ScriptExecutor {
214239 const axis = match [ 1 ] as 'x' | 'y' | 'z' ;
215240 const amplitude = parseFloat ( match [ 2 ] ) ;
216241 if ( ! isNaN ( amplitude ) ) {
217- context . entity . position [ axis ] = Math . sin ( context . time . time ) * amplitude ;
242+ const value = Math . sin ( context . time . time ) * amplitude ;
243+ const [ px , py , pz ] = context . entity . transform . position ;
244+ if ( axis === 'x' ) context . entity . transform . setPosition ( value , py , pz ) ;
245+ if ( axis === 'y' ) context . entity . transform . setPosition ( px , value , pz ) ;
246+ if ( axis === 'z' ) context . entity . transform . setPosition ( px , py , value ) ;
218247 }
219248 }
220249 }
@@ -229,7 +258,11 @@ export class ScriptExecutor {
229258 const axis = match [ 1 ] as 'x' | 'y' | 'z' ;
230259 const multiplier = match [ 2 ] ? parseFloat ( match [ 2 ] ) : 1 ;
231260 if ( ! isNaN ( multiplier ) ) {
232- context . entity . rotation [ axis ] += deltaTime * multiplier ;
261+ const [ rx , ry , rz ] = context . entity . transform . rotation ;
262+ const delta = deltaTime * multiplier ;
263+ if ( axis === 'x' ) context . entity . transform . setRotation ( rx + delta , ry , rz ) ;
264+ if ( axis === 'y' ) context . entity . transform . setRotation ( rx , ry + delta , rz ) ;
265+ if ( axis === 'z' ) context . entity . transform . setRotation ( rx , ry , rz + delta ) ;
233266 }
234267 }
235268 }
0 commit comments