Skip to content

Commit 39d5f7d

Browse files
committed
component.MagicMoveText: charsVdom class field #6479
1 parent c06e342 commit 39d5f7d

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

resources/scss/src/component/MagicMoveText.scss

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
--neo-transition-time: 500ms;
44
--neo-width : 450px;
55

6-
align-items : center;
76
background-color: #000;
87
color : #fff;
9-
display : flex;
108
font-size : 30px;
119
font-weight : bold;
1210
height : var(--neo-height);
13-
justify-content : center;
1411
width : var(--neo-width);
1512

1613
.neo-content {
17-
height : 100%;
18-
position: relative;
19-
width : 100%;
14+
align-items : center;
15+
display : flex;
16+
height : 100%;
17+
justify-content: center;
18+
position : relative;
19+
width : 100%;
2020

21-
> * {
21+
.neo-char {
2222
position : absolute;
2323
transition:
2424
color 0.2s ease-out,

src/component/MagicMoveText.mjs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class MagicMoveText extends Component {
7676
* @member {Object[]} chars=[]
7777
*/
7878
chars = []
79+
/**
80+
* @member {Object[]} charsVdom=[]
81+
*/
82+
charsVdom = []
7983
/**
8084
* @member {Number} currentIndex=0
8185
*/
@@ -287,21 +291,26 @@ class MagicMoveText extends Component {
287291
async updateChars() {
288292
let me = this,
289293
{chars, previousChars} = me,
290-
charsContainer = me.vdom.cn[0].cn,
294+
charsContainer = me.vdom.cn[0],
291295
letters = chars.map(char => char.name),
292296
char, charNode, index;
293297

298+
if (me.charsVdom.length > 1) {
299+
charsContainer.cn = me.charsVdom;
300+
await me.promiseUpdate()
301+
}
302+
294303
previousChars.forEach((previousChar, previousIndex) => {
295304
index = letters.indexOf(previousChar.name);
296305

297306
if (index > -1) {
298-
charNode = charsContainer[previousIndex];
307+
charNode = charsContainer.cn[previousIndex];
299308

300309
charNode.style.color = me.colorMove;
301310
charNode.style.left = chars[index].left;
302311
letters[index] = null
303312
} else {
304-
charNode = charsContainer[previousIndex];
313+
charNode = charsContainer.cn[previousIndex];
305314

306315
charNode.flag = 'remove'
307316
}
@@ -311,7 +320,8 @@ class MagicMoveText extends Component {
311320
if (letter !== null) {
312321
char = chars[index];
313322

314-
charsContainer.push({
323+
charsContainer.cn.push({
324+
cls : ['neo-char'],
315325
html : char.name,
316326
style: {color: me.colorFadeIn, left: char.left, opacity: 0, top: char.top}
317327
})
@@ -320,7 +330,7 @@ class MagicMoveText extends Component {
320330

321331
await me.promiseUpdate();
322332

323-
charsContainer.forEach(charNode => {
333+
charsContainer.cn.forEach(charNode => {
324334
if (charNode.flag === 'remove') {
325335
charNode.style.color = me.colorFadeOut;
326336
charNode.style.opacity = 0
@@ -332,21 +342,29 @@ class MagicMoveText extends Component {
332342
await me.promiseUpdate();
333343
await me.timeout(me.transitionTime);
334344

335-
charsContainer.sort((a, b) => parseFloat(a.style.left) - parseFloat(b.style.left));
345+
charsContainer.cn.sort((a, b) => parseFloat(a.style.left) - parseFloat(b.style.left));
336346

337-
index = charsContainer.length - 1;
347+
index = charsContainer.cn.length - 1;
338348

339349
for (; index >= 0; index--) {
340-
charNode = charsContainer[index];
350+
charNode = charsContainer.cn[index];
341351

342352
delete charNode.flag;
343353
delete charNode.style.color;
344354

345355
if (charNode.style.opacity === 0) {
346-
charsContainer.splice(index, 1)
356+
charsContainer.cn.splice(index, 1)
347357
}
348358
}
349359

360+
await me.promiseUpdate();
361+
362+
me.charsVdom = [...charsContainer.cn];
363+
364+
charsContainer.cn.length = 0;
365+
366+
charsContainer.cn.push({html: me.text});
367+
350368
await me.promiseUpdate()
351369
}
352370
}

0 commit comments

Comments
 (0)