@@ -6,6 +6,16 @@ import { Application } from '../framework/application.js';
6
6
import { ScriptAttributes } from './script-attributes.js' ;
7
7
import { ScriptType } from './script-type.js' ;
8
8
9
+ const reservedScriptNames = new Set ( [
10
+ 'system' , 'entity' , 'create' , 'destroy' , 'swap' , 'move' ,
11
+ 'scripts' , '_scripts' , '_scriptsIndex' , '_scriptsData' ,
12
+ 'enabled' , '_oldState' , 'onEnable' , 'onDisable' , 'onPostStateChange' ,
13
+ '_onSetEnabled' , '_checkState' , '_onBeforeRemove' ,
14
+ '_onInitializeAttributes' , '_onInitialize' , '_onPostInitialize' ,
15
+ '_onUpdate' , '_onPostUpdate' ,
16
+ '_callbacks' , 'has' , 'get' , 'on' , 'off' , 'fire' , 'once' , 'hasEvent'
17
+ ] ) ;
18
+
9
19
/* eslint-disable jsdoc/no-undefined-types */
10
20
/**
11
21
* @static
@@ -47,7 +57,7 @@ function createScript(name, app) {
47
57
return null ;
48
58
}
49
59
50
- if ( createScript . reservedScripts [ name ] )
60
+ if ( reservedScriptNames . has ( name ) )
51
61
throw new Error ( 'script name: \'' + name + '\' is reserved, please change script name' ) ;
52
62
53
63
var scriptType = function ( args ) {
@@ -64,6 +74,14 @@ function createScript(name, app) {
64
74
return scriptType ;
65
75
}
66
76
77
+ // Editor uses this - migrate to ScriptAttributes.reservedNames and delete this
78
+ var reservedAttributes = { } ;
79
+ ScriptAttributes . reservedNames . forEach ( ( value , value2 , set ) => {
80
+ reservedAttributes [ value ] = 1 ;
81
+ } ) ;
82
+ createScript . reservedAttributes = reservedAttributes ;
83
+
84
+
67
85
/* eslint-disable jsdoc/no-undefined-types */
68
86
/* eslint-disable jsdoc/check-examples */
69
87
/**
@@ -119,7 +137,7 @@ function registerScript(script, name, app) {
119
137
120
138
name = name || script . __name || ScriptType . __getScriptName ( script ) ;
121
139
122
- if ( createScript . reservedScripts [ name ] )
140
+ if ( reservedScriptNames . has ( name ) )
123
141
throw new Error ( 'script name: \'' + name + '\' is reserved, please change script name' ) ;
124
142
125
143
script . __name = name ;
@@ -131,32 +149,4 @@ function registerScript(script, name, app) {
131
149
ScriptHandler . _push ( script ) ;
132
150
}
133
151
134
- // reserved scripts
135
- createScript . reservedScripts = [
136
- 'system' , 'entity' , 'create' , 'destroy' , 'swap' , 'move' ,
137
- 'scripts' , '_scripts' , '_scriptsIndex' , '_scriptsData' ,
138
- 'enabled' , '_oldState' , 'onEnable' , 'onDisable' , 'onPostStateChange' ,
139
- '_onSetEnabled' , '_checkState' , '_onBeforeRemove' ,
140
- '_onInitializeAttributes' , '_onInitialize' , '_onPostInitialize' ,
141
- '_onUpdate' , '_onPostUpdate' ,
142
- '_callbacks' , 'has' , 'get' , 'on' , 'off' , 'fire' , 'once' , 'hasEvent'
143
- ] ;
144
- var reservedScripts = { } ;
145
- var i ;
146
- for ( i = 0 ; i < createScript . reservedScripts . length ; i ++ )
147
- reservedScripts [ createScript . reservedScripts [ i ] ] = 1 ;
148
- createScript . reservedScripts = reservedScripts ;
149
-
150
-
151
- // reserved script attribute names
152
- createScript . reservedAttributes = [
153
- 'app' , 'entity' , 'enabled' , '_enabled' , '_enabledOld' , '_destroyed' ,
154
- '__attributes' , '__attributesRaw' , '__scriptType' , '__executionOrder' ,
155
- '_callbacks' , 'has' , 'get' , 'on' , 'off' , 'fire' , 'once' , 'hasEvent'
156
- ] ;
157
- var reservedAttributes = { } ;
158
- for ( i = 0 ; i < createScript . reservedAttributes . length ; i ++ )
159
- reservedAttributes [ createScript . reservedAttributes [ i ] ] = 1 ;
160
- createScript . reservedAttributes = reservedAttributes ;
161
-
162
152
export { createScript , registerScript } ;
0 commit comments