@urso/core 0.4.5 → 0.4.10
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/README.md +6 -4
- package/build/js/index.js +1 -1
- package/package.json +1 -1
- package/src/js/extra/_info.js +2 -0
- package/src/js/extra/pixiPatch.js +77 -0
- package/src/js/modules/assets/service.js +10 -1
- package/src/js/modules/objects/controller.js +1 -1
- package/src/js/modules/objects/models/text.js +5 -0
- package/src/js/modules/objects/proxy.js +1 -0
- package/src/js/modules/observer/events.js +2 -0
- package/src/js/modules/scenes/controller.js +50 -2
- package/src/js/modules/scenes/model.js +0 -7
- package/src/js/modules/scenes/pixiWrapper.js +27 -1
- package/src/js/modules/scenes/service.js +36 -2
package/package.json
CHANGED
package/src/js/extra/_info.js
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModulesObjectsModelsText fillCustomColors patch
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Render the text with letter-spacing.
|
|
8
|
+
*
|
|
9
|
+
* @param text - The text to draw
|
|
10
|
+
* @param x - Horizontal position to draw the text
|
|
11
|
+
* @param y - Vertical position to draw the text
|
|
12
|
+
* @param isStroke - Is this drawing for the outside stroke of the
|
|
13
|
+
* text? If not, it's for the inside fill
|
|
14
|
+
*/
|
|
15
|
+
PIXI.Text.prototype.drawLetterSpacing = function (text, x, y, isStroke) {
|
|
16
|
+
if (isStroke === void 0) { isStroke = false; }
|
|
17
|
+
var style = this._style;
|
|
18
|
+
// letterSpacing of 0 means normal
|
|
19
|
+
var letterSpacing = style.letterSpacing;
|
|
20
|
+
// Checking that we can use moddern canvas2D api
|
|
21
|
+
// https://developer.chrome.com/origintrials/#/view_trial/3585991203293757441
|
|
22
|
+
// note: this is unstable API, Chrome less 94 use a `textLetterSpacing`, newest use a letterSpacing
|
|
23
|
+
// eslint-disable-next-line max-len
|
|
24
|
+
var supportLetterSpacing = 'letterSpacing' in CanvasRenderingContext2D.prototype
|
|
25
|
+
|| 'textLetterSpacing' in CanvasRenderingContext2D.prototype;
|
|
26
|
+
|
|
27
|
+
if ((letterSpacing === 0 || supportLetterSpacing) && (!this.fillCustomColors || this.fillCustomColors.length === 0)) { //colors patch in if state
|
|
28
|
+
if (supportLetterSpacing) {
|
|
29
|
+
this.context.letterSpacing = letterSpacing;
|
|
30
|
+
this.context.textLetterSpacing = letterSpacing;
|
|
31
|
+
}
|
|
32
|
+
if (isStroke) {
|
|
33
|
+
this.context.strokeText(text, x, y);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.context.fillText(text, x, y);
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var currentPosition = x;
|
|
41
|
+
|
|
42
|
+
var customColors = [];//colors patch block
|
|
43
|
+
var textIndexOffset = this.text.indexOf(text);
|
|
44
|
+
if (this.fillCustomColors) {
|
|
45
|
+
for (var k in this.fillCustomColors){
|
|
46
|
+
var colorsParams = this.fillCustomColors[k];
|
|
47
|
+
customColors[colorsParams.position] = colorsParams.color;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Using Array.from correctly splits characters whilst keeping emoji together.
|
|
52
|
+
// This is not supported on IE as it requires ES6, so regular text splitting occurs.
|
|
53
|
+
// This also doesn't account for emoji that are multiple emoji put together to make something else.
|
|
54
|
+
// Handling all of this would require a big library itself.
|
|
55
|
+
// https://medium.com/@giltayar/iterating-over-emoji-characters-the-es6-way-f06e4589516
|
|
56
|
+
// https://github.com/orling/grapheme-splitter
|
|
57
|
+
var stringArray = Array.from ? Array.from(text) : text.split('');
|
|
58
|
+
var previousWidth = this.context.measureText(text).width;
|
|
59
|
+
var currentWidth = 0;
|
|
60
|
+
for (var i = 0; i < stringArray.length; ++i) {
|
|
61
|
+
var currentChar = stringArray[i];
|
|
62
|
+
|
|
63
|
+
if (isStroke) {
|
|
64
|
+
this.context.strokeText(currentChar, currentPosition, y);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (customColors[textIndexOffset + i]) { //colors patch block
|
|
68
|
+
this.context.fillStyle = customColors[textIndexOffset + i];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.context.fillText(currentChar, currentPosition, y);
|
|
72
|
+
}
|
|
73
|
+
currentWidth = this.context.measureText(text.substring(i + 1)).width;
|
|
74
|
+
currentPosition += previousWidth - currentWidth + letterSpacing;
|
|
75
|
+
previousWidth = currentWidth;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
@@ -6,6 +6,7 @@ class ModulesAssetsService {
|
|
|
6
6
|
|
|
7
7
|
this._currentQuality = 'auto';
|
|
8
8
|
this._addedAssetsCache = [];
|
|
9
|
+
this.lazyLoadProcessStarted = false;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
getQuality() {
|
|
@@ -30,7 +31,7 @@ class ModulesAssetsService {
|
|
|
30
31
|
startLoad(callback) {
|
|
31
32
|
this.loadGroup(
|
|
32
33
|
this.getInstance('Config').loadingGroups.initial,
|
|
33
|
-
(() => { callback(); this.
|
|
34
|
+
(() => { callback(); this._startLazyLoad(); }).bind(this)
|
|
34
35
|
)
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -263,6 +264,14 @@ class ModulesAssetsService {
|
|
|
263
264
|
this.assets[model.loadingGroup].push(model);
|
|
264
265
|
}
|
|
265
266
|
|
|
267
|
+
_startLazyLoad() {
|
|
268
|
+
if (this.lazyLoadProcessStarted)
|
|
269
|
+
return;
|
|
270
|
+
|
|
271
|
+
this.lazyLoadProcessStarted = true;
|
|
272
|
+
this._continueLazyLoad();
|
|
273
|
+
}
|
|
274
|
+
|
|
266
275
|
_continueLazyLoad(step) {
|
|
267
276
|
if (!step)
|
|
268
277
|
step = 0;
|
|
@@ -30,7 +30,7 @@ class ModulesObjectsController {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
_createSingleObject(object, parent, doNotRefreshStylesFlag) {
|
|
33
|
-
//parse template for assets and objects (groups, components)
|
|
33
|
+
//parse template for assets and objects (groups, components) Urso.types.objects.COMPONENT Urso.types.objects.GROUP
|
|
34
34
|
if (!object._parsed) { //todo only for objects, contains components && groups in future
|
|
35
35
|
return Urso.scenes.addObject(object, parent, doNotRefreshStylesFlag);
|
|
36
36
|
}
|
|
@@ -20,6 +20,7 @@ class ModulesObjectsModelsText extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
20
20
|
this.fontStyle = Urso.helper.recursiveGet('fontStyle', params, false); //'italic'
|
|
21
21
|
this.fontWeight = Urso.helper.recursiveGet('fontWeight', params, false); // 'bold'
|
|
22
22
|
this.fill = Urso.helper.recursiveGet('fill', params, '#000000'); // gradient ['#ffffff', '#00ff99']
|
|
23
|
+
this.fillCustomColors = Urso.helper.recursiveGet('fillCustomColors', params, false); //or array [{position:12,color:'#000000'},...]
|
|
23
24
|
this.stroke = Urso.helper.recursiveGet('stroke', params, 'black');
|
|
24
25
|
this.strokeThickness = Urso.helper.recursiveGet('strokeThickness', params, 0);
|
|
25
26
|
this.dropShadow = Urso.helper.recursiveGet('dropShadow', params, false);
|
|
@@ -38,6 +39,10 @@ class ModulesObjectsModelsText extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
38
39
|
this._originalModel.text = this.text = Urso.i18n.get(this.localeId, this.localeVariables);
|
|
39
40
|
|
|
40
41
|
this._baseObject = new PIXI.Text(this.text);
|
|
42
|
+
|
|
43
|
+
if (this.fillCustomColors) {
|
|
44
|
+
this._baseObject.fillCustomColors = this.fillCustomColors;
|
|
45
|
+
}
|
|
41
46
|
};
|
|
42
47
|
|
|
43
48
|
_newLocaleHandler() {
|
|
@@ -161,6 +161,7 @@ class ModulesObjectsProxy {
|
|
|
161
161
|
'fontStyle': 'style.fontStyle',
|
|
162
162
|
'fontWeight': 'style.fontWeight',
|
|
163
163
|
'fill': 'style.fill',
|
|
164
|
+
'fillCustomColors': 'fillCustomColors',
|
|
164
165
|
'stroke': 'style.stroke',
|
|
165
166
|
'strokeThickness': 'style.strokeThickness',
|
|
166
167
|
'dropShadow': 'style.dropShadow',
|
|
@@ -28,6 +28,8 @@ class ModulesObserverConfig {
|
|
|
28
28
|
MODULES_SCENES_DISPLAY_START: 'modules.scenes.display.start',
|
|
29
29
|
MODULES_SCENES_DISPLAY_FINISHED: 'modules.scenes.display.finished',
|
|
30
30
|
MODULES_SCENES_MOUSE_NEW_POSITION: 'modules.scenes.mouse.newPosition',
|
|
31
|
+
MODULES_SCENES_PAUSE: 'modules.scenes.pause',
|
|
32
|
+
MODULES_SCENES_RESUME: 'modules.scenes.resume',
|
|
31
33
|
MODULES_SCENES_UPDATE: 'modules.scenes.update',
|
|
32
34
|
EXTRA_BROWSEREVENTS_WINDOW_PRE_RESIZE: 'extra.browserEvents.window.pre.resize',
|
|
33
35
|
EXTRA_BROWSEREVENTS_WINDOW_RESIZE: 'extra.browserEvents.window.resize',
|
|
@@ -6,38 +6,86 @@ class ModulesScenesController {
|
|
|
6
6
|
this.init();
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* init scenes mahager
|
|
11
|
+
*/
|
|
9
12
|
init() {
|
|
10
13
|
this._service = this.getInstance('Service');
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
/**
|
|
17
|
+
* display scene with name
|
|
18
|
+
* @param {String} name
|
|
19
|
+
*/
|
|
13
20
|
display(name) {
|
|
14
21
|
this._service.display(name);
|
|
15
22
|
}
|
|
16
23
|
|
|
24
|
+
/**
|
|
25
|
+
* pause scene
|
|
26
|
+
*/
|
|
27
|
+
pause() {
|
|
28
|
+
this._service.pause();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* resume scene
|
|
33
|
+
*/
|
|
34
|
+
resume() {
|
|
35
|
+
this._service.resume();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* system function for transfer loadUpdate progress to components
|
|
40
|
+
* @param {Number} loadProgress
|
|
41
|
+
*/
|
|
17
42
|
loadUpdate(loadProgress) {
|
|
18
43
|
this._service.loadUpdate(loadProgress);
|
|
19
44
|
}
|
|
20
45
|
|
|
46
|
+
/**
|
|
47
|
+
* system function, returns pixi world container
|
|
48
|
+
*/
|
|
21
49
|
getPixiWorld() {
|
|
22
50
|
return this.getInstance('PixiWrapper').getPixiWorld();
|
|
23
51
|
}
|
|
24
52
|
|
|
53
|
+
/**
|
|
54
|
+
* get template size
|
|
55
|
+
* @returns {Object}
|
|
56
|
+
*/
|
|
25
57
|
getTemplateSize() {
|
|
26
58
|
return this.getInstance('Resolutions').getTemplateSize();
|
|
27
59
|
}
|
|
28
60
|
|
|
61
|
+
/**
|
|
62
|
+
* return mouse coords related to scene
|
|
63
|
+
* @returns {Object}
|
|
64
|
+
*/
|
|
29
65
|
getMouseCoords() {
|
|
30
66
|
return this.getInstance('PixiWrapper').getCachedMouseCoords();
|
|
31
67
|
}
|
|
32
68
|
|
|
69
|
+
/**
|
|
70
|
+
* system function to add custom objects to scene like groups or components
|
|
71
|
+
* @param {Object|Array} objects
|
|
72
|
+
* @param {Object} parent
|
|
73
|
+
* @param {Boolean} doNotRefreshStylesFlag
|
|
74
|
+
*/
|
|
33
75
|
addObject(objects, parent, doNotRefreshStylesFlag) {
|
|
34
|
-
this._service.addObject(objects, parent, doNotRefreshStylesFlag);
|
|
76
|
+
return this._service.addObject(objects, parent, doNotRefreshStylesFlag);
|
|
35
77
|
}
|
|
36
78
|
|
|
79
|
+
/**
|
|
80
|
+
* global timeScale getter
|
|
81
|
+
*/
|
|
37
82
|
get timeScale() {
|
|
38
|
-
return this._service.
|
|
83
|
+
return this._service.getTimeScale();
|
|
39
84
|
}
|
|
40
85
|
|
|
86
|
+
/**
|
|
87
|
+
* global timeScale setter
|
|
88
|
+
*/
|
|
41
89
|
set timeScale(value) {
|
|
42
90
|
return this._service.setTimeScale(value);
|
|
43
91
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
class ModulesScenesModel {
|
|
2
|
-
constructor() {
|
|
3
|
-
this._isPaused = false;
|
|
4
|
-
}
|
|
5
2
|
|
|
6
3
|
loadUpdate() {
|
|
7
4
|
//just blank
|
|
@@ -23,10 +20,6 @@ class ModulesScenesModel {
|
|
|
23
20
|
//just blank
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
isPaused() {
|
|
27
|
-
return this._isPaused;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
23
|
destroy() {
|
|
31
24
|
//just blank
|
|
32
25
|
}
|
|
@@ -40,6 +40,32 @@ class ModulesScenesPixiWrapper {
|
|
|
40
40
|
this.getInstance('Resolutions');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* returns is scene paused
|
|
45
|
+
* @returns {Boolean}
|
|
46
|
+
*/
|
|
47
|
+
isPaused() {
|
|
48
|
+
return this._loopPaused;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* pause scene
|
|
53
|
+
*/
|
|
54
|
+
pause() {
|
|
55
|
+
this._loopPaused = true;
|
|
56
|
+
PIXI.spine.settings.GLOBAL_AUTO_UPDATE = false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* resume scene
|
|
61
|
+
*/
|
|
62
|
+
resume() {
|
|
63
|
+
this._loopLastCall = Date.now();
|
|
64
|
+
this._loopPaused = false;
|
|
65
|
+
this.update();
|
|
66
|
+
PIXI.spine.settings.GLOBAL_AUTO_UPDATE = true;
|
|
67
|
+
}
|
|
68
|
+
|
|
43
69
|
_setPixiSettings() {
|
|
44
70
|
PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.LINEAR;
|
|
45
71
|
PIXI.settings.TEXT_RESOLUTION = 1;
|
|
@@ -94,7 +120,7 @@ class ModulesScenesPixiWrapper {
|
|
|
94
120
|
};
|
|
95
121
|
|
|
96
122
|
update() {
|
|
97
|
-
if (!this.currentScene
|
|
123
|
+
if (!this.currentScene)
|
|
98
124
|
return;
|
|
99
125
|
|
|
100
126
|
let deltaTime = this._getDeltaTime();
|
|
@@ -21,6 +21,33 @@ class ModulesScenesService {
|
|
|
21
21
|
this._pixiWrapper.init();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* pause scene
|
|
26
|
+
*/
|
|
27
|
+
pause() {
|
|
28
|
+
this.getInstance('PixiWrapper').pause();
|
|
29
|
+
this.emit(Urso.events.MODULES_SCENES_PAUSE);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* resume scene
|
|
34
|
+
*/
|
|
35
|
+
resume() {
|
|
36
|
+
this.getInstance('PixiWrapper').resume();
|
|
37
|
+
this.emit(Urso.events.MODULES_SCENES_RESUME);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* global timeScale getter
|
|
42
|
+
*/
|
|
43
|
+
getTimeScale() {
|
|
44
|
+
const loopPaused = this.getInstance('PixiWrapper').isPaused();
|
|
45
|
+
return loopPaused ? 0 : this.timeScale;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* global timeScale setter
|
|
50
|
+
*/
|
|
24
51
|
setTimeScale(value) {
|
|
25
52
|
this.timeScale = value;
|
|
26
53
|
gsap.globalTimeline.timeScale(this.timeScale);
|
|
@@ -28,15 +55,22 @@ class ModulesScenesService {
|
|
|
28
55
|
|
|
29
56
|
addObject(objects, parent, doNotRefreshStylesFlag) {
|
|
30
57
|
const newTemplatePart = Urso.template.parse({ objects: [objects] }, true);
|
|
31
|
-
|
|
58
|
+
|
|
59
|
+
if (newTemplatePart.assets.length) {
|
|
60
|
+
Urso.assets.preload(newTemplatePart.assets, () => this._newTemplateAssetsLoadedHandler(newTemplatePart, parent, doNotRefreshStylesFlag));
|
|
61
|
+
return null; //objects will be created soon. Maybe we can return a promice
|
|
62
|
+
} else
|
|
63
|
+
return this._newTemplateAssetsLoadedHandler(newTemplatePart, parent, doNotRefreshStylesFlag);
|
|
32
64
|
}
|
|
33
65
|
|
|
34
66
|
_newTemplateAssetsLoadedHandler(newTemplatePart, parent, doNotRefreshStylesFlag) {
|
|
35
|
-
|
|
67
|
+
const objectToCreate = newTemplatePart.objects[0];
|
|
68
|
+
const result = Urso.objects.create(objectToCreate, parent, doNotRefreshStylesFlag);
|
|
36
69
|
|
|
37
70
|
//components create
|
|
38
71
|
newTemplatePart.components.forEach(component => component.create());
|
|
39
72
|
this._currentSceneTemplate.components = Urso.helper.mergeArrays(this._currentSceneTemplate.components, newTemplatePart.components);
|
|
73
|
+
return result;
|
|
40
74
|
}
|
|
41
75
|
|
|
42
76
|
display(name) {
|