@safe-engine/pixi 1.0.0
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/.github/workflows/npm-publish.yml +35 -0
- package/README.md +4 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +102 -0
- package/dist/components/EnhancedComponent.d.ts +22 -0
- package/dist/components/EnhancedComponent.d.ts.map +1 -0
- package/dist/components/EnhancedComponent.js +62 -0
- package/dist/components/GUIComponent.d.ts +72 -0
- package/dist/components/GUIComponent.d.ts.map +1 -0
- package/dist/components/GUIComponent.js +178 -0
- package/dist/components/NodeComp.d.ts +104 -0
- package/dist/components/NodeComp.d.ts.map +1 -0
- package/dist/components/NodeComp.js +420 -0
- package/dist/components/RenderComponent.d.ts +29 -0
- package/dist/components/RenderComponent.d.ts.map +1 -0
- package/dist/components/RenderComponent.js +89 -0
- package/dist/core/Color.d.ts +7 -0
- package/dist/core/Color.d.ts.map +1 -0
- package/dist/core/Color.js +6 -0
- package/dist/core/LoadingBar.d.ts +13 -0
- package/dist/core/LoadingBar.d.ts.map +1 -0
- package/dist/core/LoadingBar.js +55 -0
- package/dist/core/Scene.d.ts +6 -0
- package/dist/core/Scene.d.ts.map +1 -0
- package/dist/core/Scene.js +39 -0
- package/dist/core/Size.d.ts +10 -0
- package/dist/core/Size.d.ts.map +1 -0
- package/dist/core/Size.js +22 -0
- package/dist/core/Vec2.d.ts +20 -0
- package/dist/core/Vec2.d.ts.map +1 -0
- package/dist/core/Vec2.js +70 -0
- package/dist/core/decorator.d.ts +9 -0
- package/dist/core/decorator.d.ts.map +1 -0
- package/dist/core/decorator.js +46 -0
- package/dist/gworld.d.ts +8 -0
- package/dist/gworld.d.ts.map +1 -0
- package/dist/gworld.js +43 -0
- package/dist/helper/html-text-parser.d.ts +30 -0
- package/dist/helper/html-text-parser.d.ts.map +1 -0
- package/dist/helper/html-text-parser.js +353 -0
- package/dist/helper/utils.d.ts +17 -0
- package/dist/helper/utils.d.ts.map +1 -0
- package/dist/helper/utils.js +64 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/systems/GUISystem.d.ts +7 -0
- package/dist/systems/GUISystem.d.ts.map +1 -0
- package/dist/systems/GUISystem.js +94 -0
- package/dist/systems/RenderSystem.d.ts +15 -0
- package/dist/systems/RenderSystem.d.ts.map +1 -0
- package/dist/systems/RenderSystem.js +100 -0
- package/package.json +30 -0
- package/src/app.ts +51 -0
- package/src/components/EnhancedComponent.ts +57 -0
- package/src/components/GUIComponent.ts +147 -0
- package/src/components/NodeComp.ts +409 -0
- package/src/components/RenderComponent.ts +65 -0
- package/src/core/Color.ts +3 -0
- package/src/core/LoadingBar.ts +33 -0
- package/src/core/Scene.ts +17 -0
- package/src/core/Size.ts +21 -0
- package/src/core/Vec2.ts +52 -0
- package/src/core/decorator.ts +18 -0
- package/src/gworld.ts +17 -0
- package/src/helper/html-text-parser.ts +364 -0
- package/src/helper/utils.ts +64 -0
- package/src/index.ts +10 -0
- package/src/systems/GUISystem.ts +95 -0
- package/src/systems/RenderSystem.ts +100 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/* eslint-disable no-var */
|
|
2
|
+
/* eslint-disable quotes */
|
|
3
|
+
/* eslint-disable no-useless-escape */
|
|
4
|
+
/****************************************************************************
|
|
5
|
+
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
6
|
+
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
7
|
+
|
|
8
|
+
https://www.cocos.com/
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated engine source code (the "Software"), a limited,
|
|
12
|
+
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
|
13
|
+
to use Cocos Creator solely to develop games on your target platforms. You shall
|
|
14
|
+
not use Cocos Creator software for developing other software or tools that's
|
|
15
|
+
used for developing games. You are not granted to publish, distribute,
|
|
16
|
+
sublicense, and/or sell copies of Cocos Creator.
|
|
17
|
+
|
|
18
|
+
The software or tools in this License Agreement are licensed, not sold.
|
|
19
|
+
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
27
|
+
THE SOFTWARE.
|
|
28
|
+
****************************************************************************/
|
|
29
|
+
|
|
30
|
+
const eventRegx = /^(click)(\s)*=|(param)(\s)*=/
|
|
31
|
+
const imageAttrReg =
|
|
32
|
+
/(\s)*src(\s)*=|(\s)*height(\s)*=|(\s)*width(\s)*=|(\s)*align(\s)*=|(\s)*offset(\s)*=|(\s)*click(\s)*=|(\s)*param(\s)*=/
|
|
33
|
+
/**
|
|
34
|
+
* A utils class for parsing HTML texts. The parsed results will be an object array.
|
|
35
|
+
*/
|
|
36
|
+
export const HtmlTextParser = function () {
|
|
37
|
+
this._parsedObject = {}
|
|
38
|
+
this._specialSymbolArray = []
|
|
39
|
+
this._specialSymbolArray.push([/</g, '<'])
|
|
40
|
+
this._specialSymbolArray.push([/>/g, '>'])
|
|
41
|
+
this._specialSymbolArray.push([/&/g, '&'])
|
|
42
|
+
this._specialSymbolArray.push([/"/g, '"'])
|
|
43
|
+
this._specialSymbolArray.push([/'/g, "'"])
|
|
44
|
+
this._specialSymbolArray.push([/ /g, ' '])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
HtmlTextParser.prototype = {
|
|
48
|
+
constructor: HtmlTextParser,
|
|
49
|
+
parse: function (htmlString) {
|
|
50
|
+
this._resultObjectArray = []
|
|
51
|
+
if (!htmlString) {
|
|
52
|
+
return this._resultObjectArray
|
|
53
|
+
}
|
|
54
|
+
this._stack = []
|
|
55
|
+
|
|
56
|
+
let startIndex = 0
|
|
57
|
+
const length = htmlString.length
|
|
58
|
+
while (startIndex < length) {
|
|
59
|
+
let tagEndIndex = htmlString.indexOf('>', startIndex)
|
|
60
|
+
let tagBeginIndex = -1
|
|
61
|
+
if (tagEndIndex >= 0) {
|
|
62
|
+
tagBeginIndex = htmlString.lastIndexOf('<', tagEndIndex)
|
|
63
|
+
const noTagBegin = tagBeginIndex < startIndex - 1
|
|
64
|
+
|
|
65
|
+
if (noTagBegin) {
|
|
66
|
+
tagBeginIndex = htmlString.indexOf('<', tagEndIndex + 1)
|
|
67
|
+
tagEndIndex = htmlString.indexOf('>', tagBeginIndex + 1)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (tagBeginIndex < 0) {
|
|
72
|
+
this._stack.pop()
|
|
73
|
+
this._processResult(htmlString.substring(startIndex))
|
|
74
|
+
startIndex = length
|
|
75
|
+
} else {
|
|
76
|
+
let newStr = htmlString.substring(startIndex, tagBeginIndex)
|
|
77
|
+
const tagStr = htmlString.substring(tagBeginIndex + 1, tagEndIndex)
|
|
78
|
+
if (tagStr === '') newStr = htmlString.substring(startIndex, tagEndIndex + 1)
|
|
79
|
+
this._processResult(newStr)
|
|
80
|
+
if (tagEndIndex === -1) {
|
|
81
|
+
// cc.error('The HTML tag is invalid!');
|
|
82
|
+
tagEndIndex = tagBeginIndex
|
|
83
|
+
} else if (htmlString.charAt(tagBeginIndex + 1) === '/') {
|
|
84
|
+
this._stack.pop()
|
|
85
|
+
} else {
|
|
86
|
+
this._addToStack(tagStr)
|
|
87
|
+
}
|
|
88
|
+
startIndex = tagEndIndex + 1
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return this._resultObjectArray
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
_attributeToObject: function (attribute) {
|
|
96
|
+
attribute = attribute.trim()
|
|
97
|
+
|
|
98
|
+
const obj: any = {}
|
|
99
|
+
let header = attribute.match(/^(color|size)(\s)*=/)
|
|
100
|
+
let tagName
|
|
101
|
+
let nextSpace
|
|
102
|
+
let eventObj
|
|
103
|
+
let eventHanlderString
|
|
104
|
+
if (header) {
|
|
105
|
+
tagName = header[0]
|
|
106
|
+
attribute = attribute.substring(tagName.length).trim()
|
|
107
|
+
if (attribute === '') return obj
|
|
108
|
+
|
|
109
|
+
//parse color
|
|
110
|
+
nextSpace = attribute.indexOf(' ')
|
|
111
|
+
switch (tagName[0]) {
|
|
112
|
+
case 'c':
|
|
113
|
+
if (nextSpace > -1) {
|
|
114
|
+
obj.color = attribute.substring(0, nextSpace).trim()
|
|
115
|
+
} else {
|
|
116
|
+
obj.color = attribute
|
|
117
|
+
}
|
|
118
|
+
break
|
|
119
|
+
case 's':
|
|
120
|
+
obj.size = parseInt(attribute)
|
|
121
|
+
break
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//tag has event arguments
|
|
125
|
+
if (nextSpace > -1) {
|
|
126
|
+
eventHanlderString = attribute.substring(nextSpace + 1).trim()
|
|
127
|
+
eventObj = this._processEventHandler(eventHanlderString)
|
|
128
|
+
obj.event = eventObj
|
|
129
|
+
}
|
|
130
|
+
return obj
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
header = attribute.match(/^(br(\s)*\/)/)
|
|
134
|
+
if (header && header[0].length > 0) {
|
|
135
|
+
tagName = header[0].trim()
|
|
136
|
+
if (tagName.startsWith('br') && tagName[tagName.length - 1] === '/') {
|
|
137
|
+
obj.isNewLine = true
|
|
138
|
+
this._resultObjectArray.push({ text: '', style: { newline: true } })
|
|
139
|
+
return obj
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
header = attribute.match(/^(img(\s)*src(\s)*=[^>]+\/)/)
|
|
144
|
+
if (header && header[0].length > 0) {
|
|
145
|
+
tagName = header[0].trim()
|
|
146
|
+
if (tagName.startsWith('img') && tagName[tagName.length - 1] === '/') {
|
|
147
|
+
header = attribute.match(imageAttrReg)
|
|
148
|
+
var tagValue
|
|
149
|
+
var remainingArgument
|
|
150
|
+
let isValidImageTag = false
|
|
151
|
+
while (header) {
|
|
152
|
+
//skip the invalid tags at first
|
|
153
|
+
attribute = attribute.substring(attribute.indexOf(header[0]))
|
|
154
|
+
tagName = attribute.substr(0, header[0].length)
|
|
155
|
+
//remove space and = character
|
|
156
|
+
remainingArgument = attribute.substring(tagName.length).trim()
|
|
157
|
+
nextSpace = remainingArgument.indexOf(' ')
|
|
158
|
+
|
|
159
|
+
tagValue = nextSpace > -1 ? remainingArgument.substr(0, nextSpace) : remainingArgument
|
|
160
|
+
tagName = tagName.replace(/[^a-zA-Z]/g, '').trim()
|
|
161
|
+
tagName = tagName.toLocaleLowerCase()
|
|
162
|
+
|
|
163
|
+
attribute = remainingArgument.substring(nextSpace).trim()
|
|
164
|
+
if (tagValue.endsWith('/')) tagValue = tagValue.slice(0, -1)
|
|
165
|
+
if (tagName === 'src') {
|
|
166
|
+
switch (tagValue.charCodeAt(0)) {
|
|
167
|
+
case 34: // "
|
|
168
|
+
case 39: // '
|
|
169
|
+
isValidImageTag = true
|
|
170
|
+
tagValue = tagValue.slice(1, -1)
|
|
171
|
+
break
|
|
172
|
+
}
|
|
173
|
+
obj.isImage = true
|
|
174
|
+
obj.src = tagValue
|
|
175
|
+
} else if (tagName === 'height') {
|
|
176
|
+
obj.imageHeight = parseInt(tagValue)
|
|
177
|
+
} else if (tagName === 'width') {
|
|
178
|
+
obj.imageWidth = parseInt(tagValue)
|
|
179
|
+
} else if (tagName === 'align') {
|
|
180
|
+
switch (tagValue.charCodeAt(0)) {
|
|
181
|
+
case 34: // "
|
|
182
|
+
case 39: // '
|
|
183
|
+
tagValue = tagValue.slice(1, -1)
|
|
184
|
+
break
|
|
185
|
+
}
|
|
186
|
+
obj.imageAlign = tagValue.toLocaleLowerCase()
|
|
187
|
+
} else if (tagName === 'offset') {
|
|
188
|
+
obj.imageOffset = tagValue
|
|
189
|
+
} else if (tagName === 'click') {
|
|
190
|
+
obj.event = this._processEventHandler(`${tagName}=${tagValue}`)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (obj.event && tagName === 'param') {
|
|
194
|
+
obj.event.param = tagValue.replace(/^\"|\"$/g, '')
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
header = attribute.match(imageAttrReg)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (isValidImageTag && obj.isImage) {
|
|
201
|
+
this._resultObjectArray.push({ text: '', style: obj })
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return {}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
header = attribute.match(/^(outline(\s)*[^>]*)/)
|
|
209
|
+
if (header) {
|
|
210
|
+
attribute = header[0].substring('outline'.length).trim()
|
|
211
|
+
const defaultOutlineObject = { color: '#ffffff', width: 1 }
|
|
212
|
+
if (attribute) {
|
|
213
|
+
const outlineAttrReg = /(\s)*color(\s)*=|(\s)*width(\s)*=|(\s)*click(\s)*=|(\s)*param(\s)*=/
|
|
214
|
+
header = attribute.match(outlineAttrReg)
|
|
215
|
+
var tagValue
|
|
216
|
+
while (header) {
|
|
217
|
+
//skip the invalid tags at first
|
|
218
|
+
attribute = attribute.substring(attribute.indexOf(header[0]))
|
|
219
|
+
tagName = attribute.substr(0, header[0].length)
|
|
220
|
+
//remove space and = character
|
|
221
|
+
remainingArgument = attribute.substring(tagName.length).trim()
|
|
222
|
+
nextSpace = remainingArgument.indexOf(' ')
|
|
223
|
+
if (nextSpace > -1) {
|
|
224
|
+
tagValue = remainingArgument.substr(0, nextSpace)
|
|
225
|
+
} else {
|
|
226
|
+
tagValue = remainingArgument
|
|
227
|
+
}
|
|
228
|
+
tagName = tagName.replace(/[^a-zA-Z]/g, '').trim()
|
|
229
|
+
tagName = tagName.toLocaleLowerCase()
|
|
230
|
+
|
|
231
|
+
attribute = remainingArgument.substring(nextSpace).trim()
|
|
232
|
+
if (tagName === 'click') {
|
|
233
|
+
obj.event = this._processEventHandler(`${tagName}=${tagValue}`)
|
|
234
|
+
} else if (tagName === 'color') {
|
|
235
|
+
defaultOutlineObject.color = tagValue
|
|
236
|
+
} else if (tagName === 'width') {
|
|
237
|
+
defaultOutlineObject.width = parseInt(tagValue)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (obj.event && tagName === 'param') {
|
|
241
|
+
obj.event.param = tagValue.replace(/^\"|\"$/g, '')
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
header = attribute.match(outlineAttrReg)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
obj.outline = defaultOutlineObject
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
header = attribute.match(/^(on|u|b|i)(\s)*/)
|
|
251
|
+
if (header && header[0].length > 0) {
|
|
252
|
+
tagName = header[0]
|
|
253
|
+
attribute = attribute.substring(tagName.length).trim()
|
|
254
|
+
switch (tagName[0]) {
|
|
255
|
+
case 'u':
|
|
256
|
+
obj.underline = true
|
|
257
|
+
break
|
|
258
|
+
case 'i':
|
|
259
|
+
obj.italic = true
|
|
260
|
+
break
|
|
261
|
+
case 'b':
|
|
262
|
+
obj.bold = true
|
|
263
|
+
break
|
|
264
|
+
}
|
|
265
|
+
if (attribute === '') {
|
|
266
|
+
return obj
|
|
267
|
+
}
|
|
268
|
+
eventObj = this._processEventHandler(attribute)
|
|
269
|
+
obj.event = eventObj
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return obj
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
_processEventHandler: function (eventString) {
|
|
276
|
+
let index = 0
|
|
277
|
+
const obj = {}
|
|
278
|
+
let eventNames = eventString.match(eventRegx)
|
|
279
|
+
let isValidTag = false
|
|
280
|
+
while (eventNames) {
|
|
281
|
+
let eventName = eventNames[0]
|
|
282
|
+
let eventValue = ''
|
|
283
|
+
isValidTag = false
|
|
284
|
+
eventString = eventString.substring(eventName.length).trim()
|
|
285
|
+
if (eventString.charAt(0) === '"') {
|
|
286
|
+
index = eventString.indexOf('"', 1)
|
|
287
|
+
if (index > -1) {
|
|
288
|
+
eventValue = eventString.substring(1, index).trim()
|
|
289
|
+
isValidTag = true
|
|
290
|
+
}
|
|
291
|
+
index++
|
|
292
|
+
} else if (eventString.charAt(0) === '\'') {
|
|
293
|
+
index = eventString.indexOf('\'', 1)
|
|
294
|
+
if (index > -1) {
|
|
295
|
+
eventValue = eventString.substring(1, index).trim()
|
|
296
|
+
isValidTag = true
|
|
297
|
+
}
|
|
298
|
+
index++
|
|
299
|
+
} else {
|
|
300
|
+
//skip the invalid attribute value
|
|
301
|
+
const match = eventString.match(/(\S)+/)
|
|
302
|
+
if (match) {
|
|
303
|
+
eventValue = match[0]
|
|
304
|
+
} else {
|
|
305
|
+
eventValue = ''
|
|
306
|
+
}
|
|
307
|
+
index = eventValue.length
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (isValidTag) {
|
|
311
|
+
eventName = eventName.substring(0, eventName.length - 1).trim()
|
|
312
|
+
obj[eventName] = eventValue
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
eventString = eventString.substring(index).trim()
|
|
316
|
+
eventNames = eventString.match(eventRegx)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return obj
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
_addToStack: function (attribute) {
|
|
323
|
+
const obj = this._attributeToObject(attribute)
|
|
324
|
+
|
|
325
|
+
if (this._stack.length === 0) {
|
|
326
|
+
this._stack.push(obj)
|
|
327
|
+
} else {
|
|
328
|
+
if (obj.isNewLine || obj.isImage) {
|
|
329
|
+
return
|
|
330
|
+
}
|
|
331
|
+
//for nested tags
|
|
332
|
+
const previousTagObj = this._stack[this._stack.length - 1]
|
|
333
|
+
for (const key in previousTagObj) {
|
|
334
|
+
if (!obj[key]) {
|
|
335
|
+
obj[key] = previousTagObj[key]
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
this._stack.push(obj)
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
_processResult: function (value) {
|
|
343
|
+
if (value === '') {
|
|
344
|
+
return
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
value = this._escapeSpecialSymbol(value)
|
|
348
|
+
if (this._stack.length > 0) {
|
|
349
|
+
this._resultObjectArray.push({ text: value, style: this._stack[this._stack.length - 1] })
|
|
350
|
+
} else {
|
|
351
|
+
this._resultObjectArray.push({ text: value })
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
_escapeSpecialSymbol: function (str) {
|
|
356
|
+
for (let i = 0; i < this._specialSymbolArray.length; ++i) {
|
|
357
|
+
const key = this._specialSymbolArray[i][0]
|
|
358
|
+
const value = this._specialSymbolArray[i][1]
|
|
359
|
+
|
|
360
|
+
str = str.replace(key, value)
|
|
361
|
+
}
|
|
362
|
+
return str
|
|
363
|
+
},
|
|
364
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComponentAddedEvent,
|
|
3
|
+
Constructor, EntityManager, EventManager, EventReceive,
|
|
4
|
+
System
|
|
5
|
+
} from 'entityx-ts'
|
|
6
|
+
|
|
7
|
+
import { ComponentX, NodeComp } from '..'
|
|
8
|
+
import { GameWorld } from '../gworld'
|
|
9
|
+
|
|
10
|
+
export function registerSystem<T extends ComponentX>(component: Constructor<T>) {
|
|
11
|
+
if (GameWorld.Instance.systems.isRegistered(`${component.name}System`)) {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
class NewSystem implements System {
|
|
15
|
+
configure(event_manager: EventManager) {
|
|
16
|
+
console.log('configure registerSystem', component.name)
|
|
17
|
+
event_manager.subscribe(ComponentAddedEvent(component), this)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
receive(type: string, event: EventReceive) {
|
|
21
|
+
switch (type) {
|
|
22
|
+
case ComponentAddedEvent(component): {
|
|
23
|
+
const ett = event.entity
|
|
24
|
+
const newComp: any = ett.getComponent(component)
|
|
25
|
+
newComp.node = ett.getComponent(NodeComp)
|
|
26
|
+
break
|
|
27
|
+
}
|
|
28
|
+
default:
|
|
29
|
+
break
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
update(entities: EntityManager, events: EventManager, dt: number) {
|
|
33
|
+
for (const entt of entities.entities_with_components(component)) {
|
|
34
|
+
const comp = entt.getComponent(component)
|
|
35
|
+
// console.log('comp', comp.constructor.name, typeof comp['update'] === 'function')
|
|
36
|
+
if (comp.node.active && typeof comp['update'] === 'function') {
|
|
37
|
+
comp['update'](dt)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
Object.defineProperty(NewSystem, 'name', { value: `${component.name}System` })
|
|
43
|
+
GameWorld.Instance.systems.add(NewSystem)
|
|
44
|
+
GameWorld.Instance.systems.configureOnce(NewSystem)
|
|
45
|
+
GameWorld.Instance.listUpdate.push(NewSystem)
|
|
46
|
+
return NewSystem
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function instantiate<T>(ComponentType: Constructor<T>, data?: any): T {
|
|
50
|
+
return (ComponentType as any).create(data)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class Size {
|
|
54
|
+
constructor(width, height) {
|
|
55
|
+
this.width = width
|
|
56
|
+
this.height = height
|
|
57
|
+
}
|
|
58
|
+
width: number
|
|
59
|
+
height: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function size(width: number, height: number) {
|
|
63
|
+
return new Size(width, height)
|
|
64
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { addGameCanvasTo, app, initWorld,setupResolution } from './app'
|
|
2
|
+
export * from './components/GUIComponent'
|
|
3
|
+
export { NodeComp } from './components/NodeComp'
|
|
4
|
+
export * from './components/RenderComponent'
|
|
5
|
+
export { ComponentX, NoRenderComponentX } from './core/decorator'
|
|
6
|
+
export { SceneComponent } from './core/Scene'
|
|
7
|
+
export * from './core/Size'
|
|
8
|
+
export { Vec2 } from './core/Vec2'
|
|
9
|
+
export { GameWorld } from './gworld'
|
|
10
|
+
export { instantiate, registerSystem } from './helper/utils'
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Button, ScrollBox } from '@pixi/ui'
|
|
2
|
+
import {
|
|
3
|
+
ComponentAddedEvent, EventManager, EventReceive,
|
|
4
|
+
System
|
|
5
|
+
} from 'entityx-ts'
|
|
6
|
+
import { Sprite, Text } from 'pixi.js'
|
|
7
|
+
import { CallFunc, EaseBackIn, ScaleTo, Sequence } from 'pixi-action-ease'
|
|
8
|
+
|
|
9
|
+
import { NodeComp, SpriteRender } from '..'
|
|
10
|
+
import { ButtonComp, LabelComp, ProgressBarComp, ScrollView } from '../components/GUIComponent'
|
|
11
|
+
import { LoadingBar } from '../core/LoadingBar'
|
|
12
|
+
|
|
13
|
+
export class GUISystem implements System {
|
|
14
|
+
configure(event_manager: EventManager) {
|
|
15
|
+
event_manager.subscribe(ComponentAddedEvent(ButtonComp), this)
|
|
16
|
+
event_manager.subscribe(ComponentAddedEvent(ProgressBarComp), this)
|
|
17
|
+
event_manager.subscribe(ComponentAddedEvent(ScrollView), this)
|
|
18
|
+
event_manager.subscribe(ComponentAddedEvent(LabelComp), this)
|
|
19
|
+
// event_manager.subscribe(ComponentAddedEvent(BlockInputEventsComp), this);
|
|
20
|
+
}
|
|
21
|
+
receive(type: string, event: EventReceive) {
|
|
22
|
+
switch (type) {
|
|
23
|
+
case ComponentAddedEvent(ButtonComp): {
|
|
24
|
+
console.log('ComponentAddedEvent ButtonComp', event)
|
|
25
|
+
const ett = event.entity
|
|
26
|
+
const button = ett.getComponent(ButtonComp)
|
|
27
|
+
const nodeComp = ett.getComponent(NodeComp)
|
|
28
|
+
// const { normalImage, selectedImage, disableImage, texType, zoomScale } = button
|
|
29
|
+
const node = new Button(nodeComp.instance)
|
|
30
|
+
// node.setZoomScale(zoomScale - 1)
|
|
31
|
+
button.node = nodeComp
|
|
32
|
+
// button.node = ett.assign(new NodeComp(node, ett))
|
|
33
|
+
node.onPress.connect(() => {
|
|
34
|
+
// console.log('onPress.connect')
|
|
35
|
+
const scale = ScaleTo.create(0.12, 1.2)
|
|
36
|
+
const scaleDown = ScaleTo.create(0.12, 1)
|
|
37
|
+
const seq = Sequence.create(
|
|
38
|
+
scale,
|
|
39
|
+
CallFunc.create(() => {
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(button, 'onPress')) {
|
|
41
|
+
button.onPress(button)
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
scaleDown,
|
|
45
|
+
)
|
|
46
|
+
const ease = EaseBackIn.create(seq)
|
|
47
|
+
button.node.runAction(ease)
|
|
48
|
+
})
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
case ComponentAddedEvent(ProgressBarComp): {
|
|
52
|
+
console.log('ComponentAddedEvent ProgressBarComp', event)
|
|
53
|
+
const ett = event.entity
|
|
54
|
+
const bar = ett.getComponent(ProgressBarComp)
|
|
55
|
+
const spriteComp = ett.getComponent(SpriteRender)
|
|
56
|
+
if (!spriteComp) throw Error('ProgressBarComp need SpriteRender')
|
|
57
|
+
const { progress, mode } = bar
|
|
58
|
+
const node = new LoadingBar(mode, spriteComp.node.instance as Sprite)
|
|
59
|
+
spriteComp.node.instance.mask = node
|
|
60
|
+
bar.node = ett.assign(new NodeComp(node, ett))
|
|
61
|
+
node.progress = progress
|
|
62
|
+
break
|
|
63
|
+
}
|
|
64
|
+
case ComponentAddedEvent(ScrollView): {
|
|
65
|
+
console.log('ComponentAddedEvent ScrollView', event)
|
|
66
|
+
const ett = event.entity
|
|
67
|
+
const scroll = event.component as ScrollView
|
|
68
|
+
const { width, height } = scroll
|
|
69
|
+
const view = new ScrollBox({ width, height })
|
|
70
|
+
scroll.node = ett.assign(new NodeComp(view, ett))
|
|
71
|
+
break
|
|
72
|
+
}
|
|
73
|
+
case ComponentAddedEvent(LabelComp): {
|
|
74
|
+
console.log('ComponentAddedEvent LabelComp', event)
|
|
75
|
+
const ett = event.entity
|
|
76
|
+
const label = ett.getComponent(LabelComp)
|
|
77
|
+
const node = new Text()
|
|
78
|
+
// node.texture.rotate = 8
|
|
79
|
+
node.style.fill = '#fff'
|
|
80
|
+
label.node = ett.assign(new NodeComp(node, ett))
|
|
81
|
+
const { string = '', font = '', size } = label
|
|
82
|
+
if (font) label.setFont(font)
|
|
83
|
+
label.setSize(size)
|
|
84
|
+
label.setString(string)
|
|
85
|
+
break
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
default:
|
|
89
|
+
break
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
update() {
|
|
93
|
+
// throw new Error('Method not implemented.');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComponentAddedEvent, ComponentRemovedEvent, EventManager, EventReceive,
|
|
3
|
+
System
|
|
4
|
+
} from 'entityx-ts'
|
|
5
|
+
import { Container, Graphics, Sprite } from 'pixi.js'
|
|
6
|
+
|
|
7
|
+
import { NodeComp } from '..'
|
|
8
|
+
import { GraphicsRender, NodeRender, SpriteRender } from '../components/RenderComponent'
|
|
9
|
+
import { LoadingBar } from '../core/LoadingBar'
|
|
10
|
+
|
|
11
|
+
export enum SpriteTypes {
|
|
12
|
+
SIMPLE,
|
|
13
|
+
SLICED,
|
|
14
|
+
TILED,
|
|
15
|
+
FILLED,
|
|
16
|
+
MESH,
|
|
17
|
+
ANIMATION,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class RenderSystem implements System {
|
|
21
|
+
configure(event_manager: EventManager) {
|
|
22
|
+
event_manager.subscribe(ComponentAddedEvent(NodeRender), this)
|
|
23
|
+
event_manager.subscribe(ComponentAddedEvent(SpriteRender), this)
|
|
24
|
+
// event_manager.subscribe(ComponentAddedEvent(ImageRender), this)
|
|
25
|
+
// event_manager.subscribe(ComponentAddedEvent(MaskRender), this)
|
|
26
|
+
event_manager.subscribe(ComponentAddedEvent(GraphicsRender), this)
|
|
27
|
+
event_manager.subscribe(ComponentAddedEvent(NodeComp), this)
|
|
28
|
+
event_manager.subscribe(ComponentRemovedEvent(NodeComp), this)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
receive(type: string, event: EventReceive) {
|
|
32
|
+
switch (type) {
|
|
33
|
+
case ComponentAddedEvent(NodeRender): {
|
|
34
|
+
// console.log('NodeRender', event)
|
|
35
|
+
const ett = event.entity
|
|
36
|
+
const nodeRenderComp = ett.getComponent(NodeRender)
|
|
37
|
+
const node = new Container()
|
|
38
|
+
nodeRenderComp.node = ett.assign(new NodeComp(node, ett))
|
|
39
|
+
break
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
case ComponentAddedEvent(SpriteRender): {
|
|
43
|
+
// console.log('ComponentAddedEvent SpriteRender', event)
|
|
44
|
+
const ett = event.entity
|
|
45
|
+
const spriteComp = ett.getComponent(SpriteRender)
|
|
46
|
+
const { spriteFrame, type, fillType, fillRange, fillCenter } = spriteComp
|
|
47
|
+
const node = Sprite.from(spriteFrame)
|
|
48
|
+
if (type === SpriteTypes.FILLED) {
|
|
49
|
+
// console.log('fillType', fillType)
|
|
50
|
+
const loadingBar = new LoadingBar(fillType, node)
|
|
51
|
+
if (fillRange) loadingBar.progress = fillRange
|
|
52
|
+
if (fillCenter) loadingBar.fillCenter = fillCenter
|
|
53
|
+
spriteComp.loadingBar = loadingBar
|
|
54
|
+
// node.setMidpoint(fillCenter)
|
|
55
|
+
}
|
|
56
|
+
// node.texture.rotate = 8
|
|
57
|
+
spriteComp.node = ett.assign(new NodeComp(node, ett))
|
|
58
|
+
// spriteComp.node.anchorX = 0.5
|
|
59
|
+
// spriteComp.node.anchorY = 0.5
|
|
60
|
+
break
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// case ComponentAddedEvent(MaskRender): {
|
|
64
|
+
// console.log('MaskRender', event.component);
|
|
65
|
+
// const ett = event.entity
|
|
66
|
+
// const maskComp = event.entity.getComponent(MaskRender)
|
|
67
|
+
// const { type, segments, inverted } = maskComp
|
|
68
|
+
// const node = new cc.ClippingNode()
|
|
69
|
+
// node.setInverted(inverted)
|
|
70
|
+
// maskComp.node = ett.assign(new NodeComp(node, ett))
|
|
71
|
+
// break
|
|
72
|
+
// }
|
|
73
|
+
|
|
74
|
+
case ComponentAddedEvent(GraphicsRender): {
|
|
75
|
+
console.log('MaskRender', event.component)
|
|
76
|
+
const ett = event.entity
|
|
77
|
+
const graphics = event.entity.getComponent(GraphicsRender)
|
|
78
|
+
const { lineWidth, strokeColor, fillColor } = graphics
|
|
79
|
+
const node = new Graphics()
|
|
80
|
+
node.beginFill(fillColor)
|
|
81
|
+
node.lineStyle(lineWidth, strokeColor)
|
|
82
|
+
graphics.node = ett.assign(new NodeComp(node, ett))
|
|
83
|
+
// node.drawCircle(0, 0, 100)
|
|
84
|
+
break
|
|
85
|
+
}
|
|
86
|
+
case ComponentRemovedEvent(NodeComp): {
|
|
87
|
+
const node = event.component as NodeComp
|
|
88
|
+
if (node) {
|
|
89
|
+
node.instance.removeFromParent()
|
|
90
|
+
}
|
|
91
|
+
break
|
|
92
|
+
}
|
|
93
|
+
default:
|
|
94
|
+
break
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
update() {
|
|
98
|
+
// throw new Error('Method not implemented.');
|
|
99
|
+
}
|
|
100
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"es2017",
|
|
5
|
+
"dom"
|
|
6
|
+
],
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"target": "es5",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"strict": false,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"module": "CommonJS",
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"experimentalDecorators": true,
|
|
21
|
+
"emitDecoratorMetadata": true,
|
|
22
|
+
"noEmit": false
|
|
23
|
+
}
|
|
24
|
+
}
|